2009-12-26 44 views
1

我在调试别人的网页。有一个链接试图在弹出窗口中打开自己,其原因尚不清楚 - 在HTML(onclick = foo)中没有任何明显的引起这种情况的原因。如何捕获Javascript弹出窗口的未知原因?

禁用JavaScript意味着链接正常打开。我有Firefox/Firebug/Dom Inspector,并且想要捕获导致弹出窗口的任何JavaScript事件。由于我找不到代码,因此我被卡住了。

Firebug可以创建一种全局断点来捕获所有代码吗?有没有其他的方法来钩住这种行为并检查它?

有问题的网页是http://hijinxmusic.co.uk/,问题链接是底部附近的“绿色政策”。

谢谢你的时间。

回答

3

绿色政策文件打开一个弹出与自身负载:

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

这是green policy.htm

0

只需添加到David's answer,即获取网页上的身体负荷执行的功能http://hijinxmusic.co.uk/green%20policy.htm基本上拨打电话window.open()

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

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

此外,要添加到Russ Cam's answer,可以通过检查返回值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. 
}