Paul Lautman wrote:
Normally I ask why things DON'T work!!
However, according to what I have read at
http://subsimple.com/bookmarklets/rules.asp the bookmarklet:
javascript:q = prompt("Enter destination or leave blank for main maps
page.",
"");location='http://maps.google.co.uk/'+((q.length)?'maps?f=d&hl=en&saddr=po4+8ej&daddr= '+escape(q.replace(/
/g, "+"))+'&om=1':'')
should cause a problem because the assignment of the prompt to q is not
voided and the script is not encapsulated in a function.
So why am I not getting an error? Is it because the location assignment is
taking precedent?
Well, strictly and officially javascript
: pseudo-protocol has nothing
to do with bookmarklets: it is the closest relative of document.write
(used after document load). Yet Brendan Eich foresaw some possible
creative usage of this protocol including ill-fated psi-links and
bookmarklets see more at
<http://en.wikipedia.org/wiki/Bookmarklet#History>
That's an introductory blah-blah :-) as a comment on that funny
statement in the page you linked:
<q>If a function or an assignment returns a value, which you do not
catch, the bookmarklet will redirect to a new page that shows the
returned value. Silly, I know, but that's what it does. You can
intercept the return value by encapsulating the relevant statements
with void(...).</q>
Indeed, "silly" to see something working in the intended way instead of
the hacked way :-)
On your direct question:
As user are lasy and refusing to read any specs by their very nature
:-), "extended" javascript
: protocol usage is as simplified as
possible. As long as you don't return any value back explicetly (via
return), it presumes that you don't want to use it as a javascript
source for the next page.
In the posted bookmarklet you don't return anything explicetly, so you
are fine. Yet I would suggest to use void operator in your own
bookmarklets - just in case.