Get DOM elements of a popup for jQuery manipulation(获取用于 jQuery 操作的弹出窗口的 DOM 元素)
问题描述
我正在创建一个弹出窗口,如下所示:
I am creating a popup as follows:
var comet = {
popup: null,
newPopup: function(windowsname, w, h){
this.popup = window.open(windowsname, windowsname, 'width=' + w + ',height=' + h);
var self = comet;
var logOut= null;
$(this.popup.document).ready(function(){
logOut = self.popup.document.getElementById('logout');
console.log(logOut);
$(logOut).live('click', function(){
alert('HELLO');
return false;
})
})
},
some_function: function(){
//calling it here:
this.newPopup('index.php',1120,550);
}
}
logOut
有时(通常在第一个窗口打开时)返回 null.此外,点击处理程序永远不会通过,原始点击处理程序会运行.
The logOut
sometimes (usually on the 1st window open) returns null. Also, the click handler never goes through and the original click handler operates.
如何覆盖弹出窗口的真实点击处理程序?
这两个页面都在我的网站上,所以应该没有跨站问题..
How do I overwrite the real click handler of the popup?
Both pages are on my site, so there should be no cross site issues..
这是一个小提琴,显示了我正在尝试做的一些事情:http://jsfiddle.net/maniator/K2B3q/
Here is a fiddle that shows a little of what I am trying to do: http://jsfiddle.net/maniator/K2B3q/
推荐答案
在 Firefox 4 和 Chrome 11 中测试和工作.检查一下.
Tested and working in Firefox 4 and Chrome 11. Check it out.
$(function()
{
var comet =
{
popup: null,
newPopup: function(url, w, h)
{
this.popup = window.open(url, url, 'width=' + w + ',height=' + h);
var self = this;
this.popup.onload = function ()
{
var doc = this.document,
script = doc.createElement('script');
script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js';
script.onload = function ()
{
function setup()
{
$('#logout').click(function () { alert('It worked!'); });
}
script = doc.createElement('script');
script.textContent = "(" + setup.toString() + ")();";
doc.body.appendChild(script);
};
doc.head.appendChild(script);
};
},
foo: function()
{
this.newPopup('http://jsbin.com/amuza3/2', 600, 400);
}
};
$('#clickme').click(function ()
{
comet.foo();
});
});
这篇关于获取用于 jQuery 操作的弹出窗口的 DOM 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取用于 jQuery 操作的弹出窗口的 DOM 元素


基础教程推荐
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01