473,327 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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.
Jul 23 '05 #1
2 1325
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.'
Jul 23 '05 #2
In article <ce**********@reader2.panix.com>,
KKramsch <ka*******************@yahooPERIODcom.invalid> wrote:
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. .... -Karl


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

I you would not mind sharing.

Robert
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
13
by: AMC | last post by:
Hi, I have the below code in an asp page. When I run this page in IE or Opera it correctly displays the header info and does not redirect me to 'test.html'. However, when I run this in Netscape...
2
by: Henri Sivonen | last post by:
In order to keep subsequent code clear, I added a new method like this HTMLDivElement.prototype.foo = function(arg) { // foo for HTML div trees } Element.prototype.foo = function(arg) { //...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
9
by: WRH | last post by:
Hello I am new to asp but I made some Jscript functions which work fine. The functions contain some strings used as a registration key for some apps. It is important that these strings not be...
7
by: A Traveler | last post by:
Hello all, i was just curious if anyone whos been playing with VS2005 could tell me... In javascript (and java??) you can alter the prototypes for an object in your project. I dont remember...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
4
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option...
17
by: Rudi Hausmann | last post by:
Hi! I have some legacy code. DIVs are used to be dragged and dropped. Some checks are made. For the checks information is taken out of the DIVs id. Now my question is: Where else could I take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.