Extending browser's JavaScript lib?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KKramsch

    Extending browser's JavaScript lib?



    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. 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? Alternatively, is there a
    succinct way to tell the browser (at the beginning of a location
    bar JavaScript micro-script) to load the definitions from this
    module?

    Thanks!

    -Karl
    --
    Sent from a spam-bucket account; I check it once in a blue moon. If
    you still want to e-mail me, cut out the extension from my address,
    and make the obvious substitutions on what's left.
  • Lasse Reichstein Nielsen

    #2
    Re: Extending browser's JavaScript lib?

    KKramsch <karlUNDERSCORE kramsch@yahooPE RIODcom.invalid > writes:
    [color=blue]
    > 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.[/color]

    They are practical. They are usually called either "bookmarkle ts" (or
    "favlets" since IE decided to call their bookmarks for "Favorites" ).
    [color=blue]
    > 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?[/color]

    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.create Element("script ");
    s.src = surl;
    document.body.a ppendChild(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.callbac k) { window.callback (); }

    Then you can make a bookmarklet:

    javascript:(fun ction(){window. callback=functi on(){delete window.callback ;/*what you want to do*/};var s=document.crea teElement("scri pt");s.src="lib raryUrl.js";doc ument.body.appe ndChild(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 - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Robert

      #3
      Re: Extending browser's JavaScript lib?

      In article <ce0e3p$g5b$1@r eader2.panix.co m>,
      KKramsch <karlUNDERSCORE kramsch@yahooPE RIODcom.invalid > wrote:
      [color=blue]
      > 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.[/color]
      ....[color=blue]
      > -Karl[/color]

      Just in case I am missing something, what are you doing in these scripts?

      I you would not mind sharing.

      Robert

      Comment

      Working...