2009-11-06 130 views
1

這裏可能會出現什麼問題?這個問題似乎與正則表達式相匹配。沒有它,警報就會出現,但只要我把它放在一切都很安靜。非常感謝!通配符只是幫助查明問題,這不是目標,我確實需要正則表達式。Firefox正則表達式中的Javascript正則表達式

window.addEventListener("load", function() { myExtension.init(); }, false); 

var myExtension = { 
    init: function() { 
    var appcontent = document.getElementById("appcontent"); // browser 
    if(appcontent) 
     appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true); 
    var messagepane = document.getElementById("messagepane"); // mail 
    if(messagepane) 
     messagepane.addEventListener("load", function() { myExtension.onPageLoad(); }, true); 
    }, 

    onPageLoad: function(aEvent) { 
    var doc = aEvent.originalTarget; // doc is document that triggered "onload" event 
    // do something with the loaded page. 
    // doc.location is a Location object (see below for a link). 
    // You can use it to make your code executed on certain pages only. 

    var url = doc.location; // i have also tried doc.location.href 

    if (url.match(.*)) {alert(url);} 

    } 
} 

回答

1

match需要一個正則表達式對象。正則表達式對象可以用/regex here/(注意斜線)形式的文字構造。

使用您的代碼,您應該看到向Error Console報告的語法錯誤。

[100]要100%清除,您需要.match(/.*/)而不是.match(.*)

+0

我沒有意識到斜槓是它的一部分,他們只是分數。謝謝。 – 2009-11-06 20:41:19

+0

我認爲發佈這個答案,但我讀了二年級的問題。 – ChaosPandion 2009-11-06 20:44:05