Posted By

noah on 11/09/09


Tagged

javascript js template browser simple pattern web howto bookmarklet recipe


Versions (?)


Advertising

Website Promotion DIRECTORY is a crucial factor for all websites that need to gain better organic search engine rankings and increase website traffic.
Submitting your website as part of your Web Promotion strategy to our SEO friendly and high traffic Business Directory for review is an excellent way to gain a valuable backlink and increase your websites visibility online.

Submit Site


Who likes this?

1 person has marked this snippet as a favorite

McWatt


Bookmarklet Template: turn any snippet of JavaScript code into a Bookmarklet


Published in: HTML 






URL: http://onemorebug.com/bookmarklets

Will originally showed me how easy it is to transform random JS snippets into bookmarklets. Once you set up the HTML, just view it in Firefox, and then drag the link to your bookmarks toolbar.

The basic form is

<a href="javascript:CODE;void 0;">NAME</a>

Where CODE is any arbitrary JavaScript code, and NAME is the name you want the bookmarklet to have once it has been added to the Firefox toolbar.

And of course don't use the javascript: protocol in your HTML pages -- although it's (only!) OK for bookmarklets.

Expand | Embed | Plain Text
  1. <!-- Replace alert('hi'); with your own JavaScript. -->
  2.  
  3. <a href="javascript:alert('hi');void 0;">Hello</a>
  4.  
  5. <!-- For code that is likely to throw errors, wrap the body of the bookmarklet in a try/catch block: -->
  6.  
  7. <a href="javascript:try{doSomething()}catch(e){};void 0;">What could go wrogn?</a>

Report this snippet 

You need to login to post a comment.