📜 ⬆️ ⬇️

Bookmarklet loading external script

In the current project was the task of writing a semi-automatic page grabber. To do this, it was necessary to inject a script into the current page. Decided such a bookmarklet:

< a href = "javascript: (function () {var d = document, s;
s = d.createElement ('script');
if (typeof s! = 'object') s = d.standardCreateElement ('script');
s.src = 'http: //example.com/js/bookmarklet.js';
s.type = 'text / javascript';
d.body.appendChild (s);}) (); " > Do it! </ a >


In a more readable form:
')
( function () {
var d = document , s;
s = d.createElement ( 'script' );
if ( typeof s! = 'object' ) {
s = d.standardCreateElement ( 'script' );
}
s.src = 'http://example.com/js/bookmarklet.js' ;
s.type = 'text / javascript' ;
d.body.appendChild (s);
}) ();


Tested in IE6, IE7, FF2, FF3, Opera 9.2, Opera 9.5, Safari.

Source: https://habr.com/ru/post/28355/


All Articles