I'd like to create Chrome bookmarks that perform actions when clicked. The vast majority of them will be manipulating the URL and reloading the page. Can you make Chrome bookmarks that contain large amounts of Javascript? Maybe even jQuery?
-
2yes, but why not just try it before posting? – Matt Busche Mar 20 '13 at 15:33
-
javascript yes, but unless your javascript actually contains the jQuery library id imagine jQuery no. – PlantTheIdea Mar 20 '13 at 15:36
-
@MattBusche More interested in tips from people who may possibly have a lot of experience doing this specific thing. I've tried with minimal amounts of javascript, but I'm wondering if you can use a lot. I tried jquery, and it didn't work. So that's another thing I'm asking - is that possible? – user1729506 Mar 20 '13 at 16:04
1 Answers
The better approach would be using javascript to load an external script and append it to the <head>
of the document, this, IMO, makes it easier to work with your script as only the call to load the resources needs to be bookmarklet'd*.
Example : Load external jQuery script via Bookmarklet
For example, if you wanted to load jQuery
onto the page you're looking at, you could run this bookmarklet from your bookmark bar. (Disclaimer: Best to do a check for jQuery already on the page to avoid conflict. More on that here ).
javascript(function({var%20external_script=document.createElement('script');20external_script.type='text/javascript';20external_script.src='http://code.jquery.com/jquery-latest.js';document.getElementsByTagName('head')[0].appendChild(20external_script)})();
*Note that it has been minified and URL encoded. If you use Textmate, there's an option to "Copy Javascript to clipboard as bookmarklet" which does the minifying and encoding automatically.
Worth pointing out that you can load multiple resources into the DOM
with this method, including stylesheets.