Created
December 14, 2011 12:22
-
-
Save dsingleton/1476378 to your computer and use it in GitHub Desktop.
Bookmarklet to insert a JS file, with config query params added to the script call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (url, params) { | |
var body = document.body, | |
script = document.createElement('script'); | |
try { | |
pairs = []; | |
for(var key in params) pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key])); | |
script.setAttribute('src', url + '?' + pairs.join('&')); | |
script.setAttribute('id', params.id || 'bookmarklet'); | |
} catch (c) { | |
alert('Please wait until the page has loaded'); | |
} | |
body.appendChild(script); | |
void(0); | |
})('http://example.com/bookmarklet.js', {id: 'my-bookmarklet', cachebust: new Date()*1, user: 'alice'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment