如何捕获 Javascript 弹出窗口的未知原因?
我正在调试别人的网页。上面有一个链接试图在弹出窗口中打开自身,其原因尚不清楚——HTML 中没有任何明显的内容(onclick=foo)会导致这种情况。
禁用 JavaScript 意味着链接可以正常打开。我有 Firefox/Firebug/Dom Inspector,并且想捕获导致弹出窗口的任何 JavaScript 事件。由于找不到代码,我陷入困境。
Firebug 可以创建一种全局断点来捕获所有代码吗?是否有其他方法可以挂钩此行为并检查它?
有问题的页面是 http://hijinxmusic.co.uk/ ,问题链接是“绿色政策” “靠近底部。
感谢您抽出时间。
I am debugging someone else's web page. There is a link on it which tries to open itself in a popup window, the reason for this is unclear -- there is nothing obvious in the HTML (onclick=foo) to cause this.
Disabling JavaScript means the link opens normally. I have Firefox/Firebug/Dom Inspector and would like to trap whatever JavaScript event is leading to the popup. Since I can't find the code, I'm stuck.
Can Firebug create a sort of global breakpoint to trap all code? Is there some other way to hook into this behaviour and inspect it?
The page in question is http://hijinxmusic.co.uk/ and the problem link is "Green Policy" near the bottom.
Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
绿色策略文档会在加载时打开一个弹出窗口:
这是内部
green policy.htm
The green policy document opens a popup with itself on load:
This is inside
green policy.htm
只是添加到大卫的答案,在
http://hijinxmusic.co.uk/green%20policy.htm
页面中的主体加载时执行的函数本质上调用window.open()< /代码>
Just to add to David's answer, the function that gets executed on body load in the page at
http://hijinxmusic.co.uk/green%20policy.htm
essentially callswindow.open()
更大的问题是,您尝试在新窗口中打开的页面与用户已经在查看的窗口相同,这没有任何意义。更重要的是,如果弹出窗口阻止程序没有阻止窗口创建,则会出现弹出窗口的无限循环(加载
greenpolicy.html
,打开一个新的greenpolicy.html,加载
greenpolicy.html
等)。您希望弹出窗口发生在哪里?另外,添加到 Russ Cam的回答,您可以通过检查
window.open
的返回值来检测弹出窗口何时无法打开。我已经在 Firefox、IE、Opera 和 Safari 中成功使用了它(不需要在 Chrome 中测试)。使用提供的函数,这就是我处理被阻止的弹出窗口的方式:The bigger problem is that the page that you are trying to open in a new window is the same window that the user is already looking at, which doesn't make any sense. What's more is that if the popup blocker wasn't blocking window creation, you would have an infinite loop of popups (load
green policy.html
, open a newgreen policy.html
, loadgreen policy.html
, etc). Where did you want the popup to happen?Also, to add to Russ Cam's answer, you can detect when the popup fails to open by checking the return value of
window.open
. I have used this successfully in Firefox, IE, Opera and Safari (haven't needed to test in Chrome). Using the provided function, this is how I handle blocked popups: