KKramsch <ka*******************@yahooPERIODcom.invalid> writes:
Increasingly often I find myself using brief JavaScript scripts
as pseudo-URLs in the location bar (i.e. using the javascript:
pseudoprotocol), particularly as bookmarks.
They are practical. They are usually called either "bookmarklets" (or
"favlets" since IE decided to call their bookmarks for "Favorites").
It would be great if these mini-scripts had access to utility
functions previously defined by me in a general utilities module.
Is there any way to tell the browser to "extend" its repertoire of
JavaScript functions, and have these additional definitions remain
in force for the duration of the browser's session?
That is, to synamically load a Javascript file after the page has
loaded. That is possible, in most recent browsers. Since you are using
bookmarklets for yourself, you have control over which browser you use,
so as long as it works for you, that should be sufficient :)
To load a Javascript file, you can do:
function load(surl) {
var s = document.createElement("script");
s.src = surl;
document.body.appendChild(s);
}
This should load the script file, eventually. The problem is that you
don't know when it is done. For that, I recommend adding a single line
to the end of the library:
if (window.callback) { window.callback(); }
Then you can make a bookmarklet:
javascript
:(function(){window.callback=function(){ delete window.callback;/*what you want to do*/};var s=document.createElement("script");s.src="libraryU rl.js";document.body.appendChild(s);}())
Or, you could just make one bookmarklet to load the library, and let
the others expect it to be there. Then you have to load the library
before using the rest. It might be necessary if using IE, which has
a 500 character limit on bookmarklets.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'