Live data from Hacker News

Implementing bookmarklets in JavaScript

2ality.com

1–10 of 15 posts

Re: Implementing bookmarklets in JavaScript

#2
this is ok- and even shows you how to do async loads. an article targeting more comprehensive bookmarklets might recommend your bookmarklet should only load an external script. additionally, some discussion of postmessage would be cool. you can actually create insanely robust bookmarklets posting messages (and using views) through an iframe(s).

Re: Implementing bookmarklets in JavaScript

#3
post #2

this is ok- and even shows you how to do async loads. an article targeting more comprehensive bookmarklets might recommend your bookmarklet should only load an external script. additionally, some discussion of postmessage would be cool. you can actually create insanely robust bookmarklets posting messages (and using views) through an iframe(s).

Do you have an example of something cool done with postmessage? I've never seen that term before.

Re: Implementing bookmarklets in JavaScript

#4
post #2

this is ok- and even shows you how to do async loads. an article targeting more comprehensive bookmarklets might recommend your bookmarklet should only load an external script. additionally, some discussion of postmessage would be cool. you can actually create insanely robust bookmarklets posting messages (and using views) through an iframe(s).

Do you have an example of something cool done with postmessage? I've never seen that term before.

i threw some example code [1] on gist to supplement my comment. i modified it a bit and didn't test it- but it used to work- so probably still good for reference. it's also not very pretty. questions, comments, concerns welcome.

essentially, it gives you two-way communication to your server on any arbitrary domain- that's pretty powerful!

[1] https://gist.github.com/1020251

Re: Implementing bookmarklets in JavaScript

#6
post #4

Earlier quoted context omitted.

Do you have an example of something cool done with postmessage? I've never seen that term before.

i threw some example code [1] on gist to supplement my comment. i modified it a bit and didn't test it- but it used to work- so probably still good for reference. it's also not very pretty. questions, comments, concerns welcome. essentially, it gives you two-way communication to your server on any arbitrary domain- that's pretty powerful! [1] https://gist.github.com/1020251

Instead of polling, you can define event handlers for 's onload and onreadystatechange event to detect when jQuery gets loaded. See Ben Alman's jQuery bookmarklet generator for an example: http://benalman.com/code/test/jquery-run-code-bookmarklet/

Re: Implementing bookmarklets in JavaScript

#7
Bookmarklets are awesome except they involve more user interaction than should be needed. I feel like almost every time I could use a bookmarklet, a plugin would do more with just as much user initiative.

They also don't have a favicon (or I haven't seen one in FF4) without a user pre-visiting a destination page, so they look unpolished.

Re: Implementing bookmarklets in JavaScript

#8
post #2

this is ok- and even shows you how to do async loads. an article targeting more comprehensive bookmarklets might recommend your bookmarklet should only load an external script. additionally, some discussion of postmessage would be cool. you can actually create insanely robust bookmarklets posting messages (and using views) through an iframe(s).

I see you use the (function() {…})(); syntax in your gist, while the linked article uses (function() {…}()); I tried some simple experiment, even passing a param in the outer parens, and both seemed to work the same, and ok. Is one of these "right" and the other one "wrong"?

Re: Implementing bookmarklets in JavaScript

#9
post #8
post #2

this is ok- and even shows you how to do async loads. an article targeting more comprehensive bookmarklets might recommend your bookmarklet should only load an external script. additionally, some discussion of postmessage would be cool. you can actually create insanely robust bookmarklets posting messages (and using views) through an iframe(s).

I see you use the (function() {…})(); syntax in your gist, while the linked article uses (function() {…}()); I tried some simple experiment, even passing a param in the outer parens, and both seemed to work the same, and ok. Is one of these "right" and the other one "wrong"?

The former give the following message in http://jslint.com

  Problem at line 1 character 17: Move the invocation into the parens that contain the function.
Crockford seems to prefer the latter but I don't know why.

Re: Implementing bookmarklets in JavaScript

#10
One of the best things about bookmarklets is that they work on mobiles too.

There's a great collection of bookmarklets at https://www.squarefree.com/bookmarklets/ (Fron the same guy who tracks changes in Firefox's nightly builds: http://www.squarefree.com/burningedge/ )

You can also turn bookmarklets into GreaseMonkey scripts so they can be ran automatically on certain sites (in Firefox): http://www.squarefree.com/2005/05/16/bookmarklets-to-user-sc...

Post reply on HN