Skip to content

Instantly share code, notes, and snippets.

@cou929
Created September 20, 2010 14:41
Show Gist options
  • Save cou929/587995 to your computer and use it in GitHub Desktop.
Save cou929/587995 to your computer and use it in GitHub Desktop.
Simple code snippet for loading external script from a bookmarklet.
/**
* load-external-script-snippet.js
* Kosei Moriyama <cou929@gmail.com>
*
* Simple code snippet for loading external script from a bookmarklet.
* Replace example url of script to your target script url before use.
*/
(function() {
var u = 'http://example.com/bookmarklet.js';
var s = document.createElement('script');
s.type = 'text/javascript';
s.charset = 'utf-8';
s.src = u;
document.body.appendChild(s);
})()
// compressed version
javascript:(function(d,u,s){s=d.createElement('script');s.type='text/javascript';s.charset='utf-8';s.src=u;d.body.appendChild(s)})(document,'http://example.com/bookmarklet.js')
@leoruizb
Copy link

leoruizb commented Nov 10, 2018

Hi

I am trying test your code but it doesn´t work for me:

http://www.geoeduca.org/gt_uni/forms/forma2.html

code snippet bookmarklet:
javascript:(function(d,u,s){s=d.createElement('script');s.type='text/javascript';s.charset='utf-8';s.src=u;d.body.appendChild(s)})(document,'http://www.geoeduca.org/gt_uni/forma2.js')

file: forma2.js
function(){
document.loginForm.userName.value="Your Name";
document.loginForm.userPassword.value="passw ord";
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment