Load external JS from bookmarklet? Load external JS from bookmarklet? javascript javascript

Load external JS from bookmarklet?


2015 Update

Content security policy will prevent this from working in many sites now. For example, the code below won't work on Facebook.

2008 answer

Use a bookmarklet that creates a script tag which includes your external JS.

As a sample:

javascript:(function(){document.body.appendChild(document.createElement('script')).src='** your external file URL here **';})();


Firefox and perhaps others support multiline bookmarklets, no need for one liner. When you paste in the code it just replaces newlines with spaces.

javascript:var q = document.createElement('script');q.src = 'http://svnpenn.github.io/bm/yt.js';document.body.appendChild(q);void 0;

Example


If I can add method tested in FF & Chrome (for readibility split to multiple lines):

javascript:var r = new XMLHttpRequest();           r.open("GET", "https://...my.js", true);           r.onloadend = function (oEvent) {               new Function(r.responseText)();               /* now you can use your code */           };           r.send();           undefined