[thelist] Javascript bookmarklet to populate fields takes me to new page — why?

ben morrison morrison.ben at gmail.com
Wed Sep 23 04:54:10 CDT 2009

On Wed, Sep 23, 2009 at 10:46 AM, Barney Carroll
<barney.carroll at gmail.com> wrote:
> Thanks Ben,
>> You could look into creating a bookmarklet that inserts the JS into the
> page.
> javascript:(function(){document.body.appendChild(document.createElement('script')).src='**
>> your external file URL here **';})();
>> That way you can keep maintenance of the files too :D
> Not too bad an idea — I might stick to this because as you say, the script
> can then evolve over time without managing bookmarks.
> So it seems that what stops scripts entered via the URL bar from misbehaving
> is an appended '()'. Why is that?

() at the end just tells the js to run the anynomous function[0]

But the difference is its only 1 function running.

Your example had 2 lines of javascript execution, the first 1 ran in
page, the second one just ended up as a new doc - a little odd yes.


[0] http://www.hedgerwow.com/360/dhtml/js-anonymous-function-patterns.html
Ben Morrison

More information about the thelist mailing list