Bookmarklet, loading an external script

    The current project was the task of writing a semi-automatic grabber of pages. To do this, it was necessary to inject the script into the current page. I decided with this bookmarklet:

    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!


    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.

    Also popular now: