Skip to content

Instantly share code, notes, and snippets.

@laander
Created December 22, 2010 00:09
Show Gist options
  • Save laander/750857 to your computer and use it in GitHub Desktop.
Save laander/750857 to your computer and use it in GitHub Desktop.
A nifty tool for creating hosted javascript browser bookmarklets supporting jQuery
/**
* Hosted jQuery Bookmarklet
* @description A nifty tool for creating hosted javascript browser bookmarklets supporting jQuery
* @author Laander (http://laander.com) at Konscript (http://konscript.com)
* @gist https://gist.github.com/gists/750857
*/
/**
* Usage:
* The following snippet should be the link saved as a bookmarklet by the user.
* Instead of a regular website adress, this will execute the remotely located javascript on
* the page where the user is currently located. Replace the test address with you own.
*
* <a alt="My Bookmarklet" href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://mysite.com/hosted-bookmarlet.jquery.js');})();">Drag to Bookmarks Bar to save this Bookmarklet</a>
*/
function run() {
// Your script here.
// Remember that you have full access to the DOM on which page the bookmarklet is loaded,
// which means that you can manipulate the content of other sites on-the-fly
}
function loadJQ() {
// Load newest jQuery if it isn't already
if (typeof jQuery == 'undefined') {
var jQuery = document.createElement('script');
jQuery.type = 'text/javascript';
jQuery.onload = run;
jQuery.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
document.body.appendChild(jQuery);
}
// Activate no-conflict mode, remember to call jQuery().function instead of $().function
jQuery.noConflict();
}
loadJQ();
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment