【发布时间】:2009-07-07 16:16:07
【问题描述】:
我有 Javascript 可以打开另一个窗口并为所有链接注册一个点击处理程序:
//Inside a class somewhere
this.file_browser_window = $(window.open("/filebrowser", "file_browser_window",
"width=800,height=600"))
Event.observe(this.file_browser_window, 'load', function (){
//This is the event I am after
Event.observe(this.file_browser_window, 'click', handle_click_in_browser);
}.bindAsEventListener(this));
// The Handler function
function handle_click_in_browser(evt){
evt.stop();
url = evt.target.href;
if(url && url.endsWith('.png')){
console.log("Image clicked");
//REMMEMBER THIS URL ON MAIN PAGE
this.close();
}
else{
console.log("Regular stuff clicked", this);
this.location = url; //<-- THIS is the breaking point
}
}
但是,当用户单击该弹出窗口中的某个链接时,当页面重新加载时,我的 CLICK 处理程序消失了!
弹出窗口中的链接指向同一个域。
现在,我无法更改弹出窗口中的源代码(html)。我需要捕捉用户点击的链接标签(如果它指向图片)的 href。
如果有人感兴趣,我会在弹出窗口中运行django-filebrowser。
【问题讨论】:
-
弹窗中的链接是否指向同一个域中的页面?