小编Tom*_*ica的帖子

window.open返回null并在内联脚本中失败,但在控制台中运行

我正在使用Smarty模板系统.其功能之一是输出脚本的可能性,该脚本为每个页面生成调试信息.在这里您可以看到生成代码的示例:

<script type="text/javascript">
//<![CDATA[

setTimeout(function() {  //Attempt to fix the issue with timeout
    var _smarty_console = window.open("about:blank","md5hash","width=680,height=600,resizable,scrollbars=yes");
    console.log(_smarty_console);  //Trying to log it
    if(_smarty_console!=null) {
      _smarty_console.document.write("<!DOCTY... lots of HTML ...<\/html>\n");
      _smarty_console.document.close();
    }
}, 5000);
//]]> 
</script>
Run Code Online (Sandbox Code Playgroud)

问题是,window.open函数总是返回null.我试图延迟它setTimeout但没有改变.当我复制代码并在Firebug控制台中运行它时,它可以正常工作.页面上没有其他脚本.该页面使用严格的XHTML.脚本就在此之前</body>.

javascript window.open

15
推荐指数
1
解决办法
2万
查看次数

在谷歌浏览器中,getBoundingClientRect().x未定义

我在画布上进行绘图操作.在我看来,相对于画布左上角计算光标位置的最佳方法是使用.getBoundingClientRect():

HTMLCanvasElement.prototype.relativeCoords = function(event) {
  var x,y;
  //This is the current screen rectangle of canvas
  var rect = this.getBoundingClientRect();

  //Recalculate mouse offsets to relative offsets
  x = event.clientX - rect.x;
  y = event.clientY - rect.y;
  //Debug
  console.log("x(",x,") = event.clientX(",event.clientX,") - rect.x(",rect.x,")");
  //Return as array
  return [x,y];
}
Run Code Online (Sandbox Code Playgroud)

我认为这段代码没有错,它可以在firefox中运行.测试一下.

但是在谷歌浏览器中,我的调试行打印出来:

x(NaN)= event.clientX(166) - rect.x(undefined)

我究竟做错了什么? 这不符合规格吗?

编辑:似乎我的代码遵循W3C:

从规格:

getBoundingClientRect()

getBoundingClientRect()调用该方法时,必须返回以下算法的结果:

  1. 让list成为调用getClientRects()此方法的同一元素的调用结果.

  2. 如果列表为空,则返回一个DOMRect对象x,其中y, …

javascript google-chrome getboundingclientrect

15
推荐指数
1
解决办法
2万
查看次数

将webpack与现有的requirejs应用程序一起使用

我正在使用在其构建系统中使用RequireJS 的现有应用程序(canvas-lms).我正在开发一个插入Canvas的伪独立应用程序(Canvas一句中的"client_app").这是一个仅限于fontend的应用程序,可以将API调用回主机Canvas应用程序.详细信息对我的问题并不十分重要 ​​- client_app需要做的就是拥有一个构建脚本,该脚本在Canvas应用程序树中定义的位置吐出一个JS文件.

我正在尝试使用Webpack构建我的应用程序而不是RequireJS.如果我保持所有依赖项都是自包含的(例如npm-install我需要的所有内容),那么一切都很有效; 但是,Canvas已经提供了许多这些依赖项(例如React,jQuery),而在jQuery的情况下,它提供了一个我想要使用的修补版本.这是我开始遇到问题的地方.

让React工作很容易; Canvas用bower安装它,所以我能够alias在我的webpack配置中添加一个指向它:

alias: {
  'react': __dirname + '/vendor/canvas/public/javascripts/bower/react/react-with-addons',
}
Run Code Online (Sandbox Code Playgroud)

(__dirname + /vendor/canvas是我的应用程序树中的符号链接到主机Canvas应用程序的树)

我遇到麻烦的地方是尝试加载提供的jQuery副本.

Canvas具有以下jQuery结构:

/public/javascripts/jquery.js:

define(['jquery.instructure_jquery_patches'], function($) {
  return $;
});
Run Code Online (Sandbox Code Playgroud)

/public/javascripts/jquery.instructure_jquery_patches.js:

define(['vendor/jquery-1.7.2', 'vendor/jquery.cookie'], function($) {
  // does a few things to patch jquery ...
  // ...
  return $;
});
Run Code Online (Sandbox Code Playgroud)

/public/javascripts/vendor/jquery.cookie.js - 看起来像标准的jquery.cookie插件,包含在AMD定义中:

define(['vendor/jquery-1.7.2'], function(jQuery) {

jQuery.cookie = function(name, value, options) {
    //......
};

});
Run Code Online (Sandbox Code Playgroud)

最后是/public/javascripts/vendor/jquery-1.7.2.js.不会粘贴它,因为它是bog标准的jQuery1.7.2,除了AMD定义已经匿名 - 将其恢复为股票行为并没有什么区别.

我希望能够做类似的事情 …

javascript requirejs webpack

15
推荐指数
1
解决办法
1万
查看次数

如何与私人嵌套课程成为朋友

我以为我可以这样做:

class TestA
{
private:
  class Nested
  {

  };
};

class TestB
{
public:
  friend class TestA;
  friend class TestA::Nested;
};
Run Code Online (Sandbox Code Playgroud)

但是我得到一个错误:

错误C2248'TestA :: Nested':无法访问在类中声明的私有类

有没有办法与私人嵌套班相处?我该怎么做?

尝试在MSVC 2017(C ++ 17)中编译MSVC 6项目时遇到此错误。我想那是可行的。

c++ friend c++17

15
推荐指数
2
解决办法
841
查看次数

是否可以在不暂停执行的情况下在Visual Studio 2010中编辑和继续?

我最近看了一下Notch的Ludum Dare直播.在他的游戏中,他广泛使用Eclipse的hotswap功能.(这是我所指的http://www.twitch.tv/notch/b/302823358?t=86m30s的视频)

我想用C#和XNA做同样的事情.幸运的是,Visual Studio具有"编辑并继续"功能.但是,我想在运行时编辑我的渲染代码而不是暂停它.

我可以设置Visual Studio来做同样的事情吗?我注意到有一个复选框Break all processes when one process breaks.是否可以在另一个线程中设置我的渲染循环,以便在我进行更改时游戏保持渲染?

xna visual-studio-2010 hotswap edit-and-continue

14
推荐指数
2
解决办法
3088
查看次数

CORS标题'Access-Control-Allow-Origin'不匹配......但确实如此!

我在Java中创建了一个非常简单的JSON API.它实际上是一个项目Zomboid mod,它提供对象坐标.这就是我的HTTP处理程序的样子:

public class JSONZomboid implements HttpHandler
{
    @Override
    public void handle(HttpExchange t) throws IOException {
        // HEADERS
        Headers headers = t.getResponseHeaders();
        headers.set("Content-Type", "text/json");   
        headers.set("Access-Control-Allow-Origin", "pzmap.crash-override.net");                 
        t.sendResponseHeaders(200,0);
        //BODY
        OutputStream os = t.getResponseBody();
        os.write("{\n".getBytes());
          // generate JSON here
        os.write("}".getBytes());
        os.close();
    }
}
Run Code Online (Sandbox Code Playgroud)

我想使用userscript将它加载到Project Zomboid地图项目中,这意味着我需要启用CORS来连接.这是通过简单的代码完成的:

PlayerRenderer.prototype.fetchInfo = function() {
  $.get("http://127.0.0.1:8000/test", {}, this.displayPoints.bind(this));
}
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

警告:阻止跨源请求:同源策略不允许在http://127.0.0.1:8000/test上读取远程资源.(原因:CORS标题'Access-Control-Allow-Origin'与'pzmap.crash-override.net'不匹配).

即使在控制台中我也能清楚地看到错误是误导性的:

图片描述

如果我还没有讨厌CORS,我现在就开始讨厌它了.你能否告诉我allow origin header中的实际字符串是什么?

javascript firebug http-headers cors

14
推荐指数
4
解决办法
1万
查看次数

Qt中的事件传播

我只是关于Qt事件系统QEvent的文档.我对该QObject::event()方法的行为感兴趣.文件说明:

此虚函数接收事件到对象,如果事件e被识别和处理,则应返回true.

falseevent()方法返回时的预期行为是什么?还有什么办法来处理这个事件?事件是否自动转发到父对象?

注意:我知道源代码可用,而且我有副本.我理想地寻找解决此行为的一些文档.

qt qt-events

13
推荐指数
1
解决办法
9829
查看次数

我收到错误代码参考中不存在的错误 - 浏览器错误

https://developers.google.com/recaptcha/docs/verify#error_code_reference

我使用了 reCAPTCHA v3 并得到了官方文档中未列出的错误代码。

{
  success : false,
  error-codes : [ "browser-error" ]
}
Run Code Online (Sandbox Code Playgroud)

它只发生在 safari 浏览器中。

原因是什么?

recaptcha-v3 recaptcha-enterprise

13
推荐指数
1
解决办法
3222
查看次数

NullPointerException:尝试调用虚方法'int android.graphics.Bitmap.getWidth()'

public class CategoryAdapter extends BaseAdapter {
Context context;
ArrayList<ModelCategory> model;
LayoutInflater layoutInflater;

public CategoryAdapter(Activity activity, ArrayList<ModelCategory> model) {
    this.model = model;
    this.context = activity;
}

@Override
public int getCount() {
    return model.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder viewHolder = null;
    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        viewHolder = new ViewHolder();
        convertView = …
Run Code Online (Sandbox Code Playgroud)

android exception bitmap

12
推荐指数
1
解决办法
2万
查看次数

如何获得用可编辑的JComboBox编写的值?

我一直在寻找,似乎每个人都只使用JComboBox#getSelectedItem.但我的组合框是可编辑的,用户可以输入任何内容.该getSelectedItem方法返回组合框中的一个实际项目,而不是在字段中输入的字符串.

图片描述

如果我的盒子包含"Bar"和"Item"并且用户输入"Foo",我想得到"Foo"!

为什么getSelectedItem不起作用

有人指出,getSelectedItem它也会返回输入的字符串.但是没有指出,这仅在用户停止编辑字段后才有效.我附上了这些事件监听器:

Component[] comps = input.getComponents();
//Third is the text field component
comps[2].addKeyListener(new KeyListener() {
  public void keyTyped(KeyEvent e) {
    doSomething();
  }
});
//Also fire event after user leaves the field
input.addActionListener (new ActionListener () {
    @Override
    public void actionPerformed(ActionEvent e) {
      doSomething();
    }
});
Run Code Online (Sandbox Code Playgroud)

这就是结果:

KeyEvent:
 JComboBox.getEditor().getItem() = 6  
 JComboBox.getSelectedItem()     = null
KeyEvent:
 JComboBox.getEditor().getItem() = 66
 JComboBox.getSelectedItem()     = null
KeyEvent:
 JComboBox.getEditor().getItem() = 666
 JComboBox.getSelectedItem()     = …
Run Code Online (Sandbox Code Playgroud)

java jcombobox

11
推荐指数
1
解决办法
6916
查看次数