load an external js, when moving to another page
I have this button :
<a onclick="return false;" href='javascript:(function(){s=document.createElement("script");s.type="text/javascript";s.src="http://localhost/demogen/demogen.js";document.body.appendChild(s);})();' class="Button">siteDEMO < /a>
that users can drag to their browser's toolbar, and when t开发者_Python百科hey go to their website, by clicking on the button on the toolbar, it loads demogen.js script.
Now I want to add an event that when this script is loaded in a page, and the user clicks on a link, when browser moved to next page, load the script for that page again. any idea ?
You can pass the url of the js in the url of the next page.
i.e:
var jsURL = '/demogen/demogen.js',
nextURL = 'nextPage.html?js=' + encodeURIComponent(jsURL);
Then in the next page retrieve the js path by:
var jsURL = decodeURIComponent(window.location.search.substring(4));
To finally load the script in the next page inserting a SCRIPT tag in the HEAD or BODY with it's src attribute pointing to the jsURL value
This isn't possible with a bookmarklet. Bookmarklets load these scripts for the current page by actually injecting a <script>
tag into the DOM. This script that's been injected is only able to live within the page its been injected into.
精彩评论