You could add an event listener to the URL bar (I explained in a comment why the code in the answer to your old question didn't work) but frankly - this isn't the best way. URL bar contents can also change if the user starts typing into it for example. And the user could even choose to remove the URL bar from the browser window.
The best way to achieve this is implementing a progress listener. You can find example code and explanation on https://developer.mozilla.org/en/Code_snippets/Progress_Listeners. You would be interested in calls to the onLocationChange
method, that will happen every time the URL bar contents need to change (also when the user switches between tabs).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…