开发者

Greasemonkey script injection

开发者 https://www.devze.com 2022-12-21 09:22 出处:网络
I\'m using greasemonkey to inject a script into every page that loads in my browser. The problem that i\'m facing now is that, if the browser moves from one page to another within the same domain, gre

I'm using greasemonkey to inject a script into every page that loads in my browser. The problem that i'm facing now is that, if the browser moves from one page to another within the same domain, greasemonkey doesn't inject my script again. For example, I'm at google.com, so when my browser loads this page, my script is injec开发者_如何转开发ted. Now, say i type some search string and click on search. The browser takes me to another page with the primary url as google.com . Here, my script isn't injected.

How do i solve such an issue.

Any help/comments would be appreciated.


click on search. The browser takes me to another page

Actually it doesn't. In the new Google interface, what it has actually done is to remain on the existing page, but replace the search form with a list of search results, fetched via XMLHttpRequest. It then changes the #fragmentIdentifier part of the URL to store the search information so that you can still navigate and bookmark the URL as if the search results were a different page.

Here, my script isn't injected

No, but your script is still present, from when it was loaded at the search form.

If you need your script to detect that the #hash part of the URL has changed, representing an internal navigation, there is the HTML5 onhashchange event. However it is only supported in Firefox 3.6 (and a few other browsers), so for extensions compatibility with older Firefoxen you would need to use a setInterval-style poller checking location.hash to determine when this happens.


You could set @include * if you want your greasemonkey script load on everypage

// @include        *
0

精彩评论

暂无评论...
验证码 换一张
取 消