如何捕获 Javascript 弹出窗口的未知原因?

发布于 2024-08-16 06:26:07 字数 395 浏览 4 评论 0原文

我正在调试别人的网页。上面有一个链接试图在弹出窗口中打开自身,其原因尚不清楚——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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一人独醉 2024-08-23 06:26:07

绿色策略文档会在加载时打开一个弹出窗口:

<body onload="MM_openBrWindow('green%20policy.htm','green','width=900,height=600')">

这是内部 green policy.htm

The green policy document opens a popup with itself on load:

<body onload="MM_openBrWindow('green%20policy.htm','green','width=900,height=600')">

This is inside green policy.htm

凉城已无爱 2024-08-23 06:26:07

只是添加到大卫的答案,在 http://hijinxmusic.co.uk/green%20policy.htm 页面中的主体加载时执行的函数本质上调用 window.open()< /代码>

function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}

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 calls window.open()

function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}
纸伞微斜 2024-08-23 06:26:07

更大的问题是,您尝试在新窗口中打开的页面与用户已经在查看的窗口相同,这没有任何意义。更重要的是,如果弹出窗口阻止程序没有阻止窗口创建,则会出现弹出窗口的无限循环(加载greenpolicy.html,打开一个新的greenpolicy.html,加载greenpolicy.html等)。您希望弹出窗口发生在哪里?

另外,添加到 Russ Cam的回答,您可以通过检查window.open的返回值来检测弹出窗口何时无法打开。我已经在 Firefox、IE、Opera 和 Safari 中成功使用了它(不需要在 Chrome 中测试)。使用提供的函数,这就是我处理被阻止的弹出窗口的方式:

function MM_openBrWindow(theURL,winName,features) { //v2.0
    if ( !window.open(theURL, winName, features) ) {
        // Window failed to open:
        // show a HTML dialog/popover that prompts the user to allow
        // popups from this site, along with a `cancel` and `try again`
        // button.  The `try again` button will attempt to open the
        // window again with the provided parameters
        dialog.popupBlockedNotice.open(arguments);
    }
    // Window opened successfully.
}

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 new green policy.html, load green 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:

function MM_openBrWindow(theURL,winName,features) { //v2.0
    if ( !window.open(theURL, winName, features) ) {
        // Window failed to open:
        // show a HTML dialog/popover that prompts the user to allow
        // popups from this site, along with a `cancel` and `try again`
        // button.  The `try again` button will attempt to open the
        // window again with the provided parameters
        dialog.popupBlockedNotice.open(arguments);
    }
    // Window opened successfully.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文