Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在子窗口上绑定jQuery事件_Javascript_Jquery - Fatal编程技术网

Javascript 在子窗口上绑定jQuery事件

Javascript 在子窗口上绑定jQuery事件,javascript,jquery,Javascript,Jquery,我有一个包含以下javascript的页面: var w = window.open("somePage.html", '', 'width=500, height=500'); $(w).bind('someEvent', function() { alert('I see the event!'); }); 在somePage.html上,我试图触发事件: $(window).trigger('someEvent', ''); 事件不会触发(但是,如果在同一页上进行事件绑定和触发器,则会

我有一个包含以下javascript的页面:

var w = window.open("somePage.html", '', 'width=500, height=500');
$(w).bind('someEvent', function() { alert('I see the event!'); });
somePage.html上,我试图触发事件:

$(window).trigger('someEvent', '');
事件不会触发(但是,如果在同一页上进行事件绑定和触发器,则会触发)。我尝试过各种绑定,比如使用this和this.window

我是不是从绑定端引用了正确的对象

(我正在Chrome和Firefox中进行测试)

编辑:

很好地解决了这个问题:
&

我认为问题在于,
$
仍然在主机窗口中引用jquery。如果您这样做:

var w = window.open("somePage.html", '', 'width=500, height=500');
var $ = w.$;
$(w).bind('someEvent', function() { alert('I see the event!'); });

你应该准备好了。

你能设置一个jsfiddle.net吗?一个jsfiddle.)哇,我不知道你可以引用另一个JSFIDLE,谢谢!