2009-12-26 45 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. 
}