...

From OLD to DOM

Jerome
03-18-2003, 05:44 PM
Hi,

First of all DOM in Dutch means not so clever!

Secondly, I like to replace a function (mentioned below) to DOM or even W3C standards which basicly does:

A. download *.js file (with loaded check)
B. read-out the array it's containing

Currently i handle things the (very) old way with a hidden iframe:

1. write html in iframe to download *.js file
2. Do this a second time to be sure the file is downloaded?!? and handle array
3. bring array results to function to make string
4. place string in DIV with documentGetElementById

Does anyone has a simular function available / can bring me in the right direction?

Thanks for Your effort,

Jerome

liorean
03-18-2003, 06:36 PM
In fact, for the moment I'm just writing a testpage for this kind of action. I've written a couple of bookmarklets that use this mechanism, but they don't work in op7 and saf/konq because of different problems.

Here's a mechanism for moz/ie5m/iew:


/*\ Bookmarklet href code (IE5.5+Win, IE5Mac, Moz)
* by: Liorean <http://liorean.web-graphics.com/> <mailto:liorean@user.bip.net>
* url: <http://liorean.web-graphics.com/bookmarklets/bookmarklet.js>
\*/
javascript:// Protocol, will be treated as label if run
(function(){// Wrap everything in an anonymous function to provide a private scope to the bookmarklet
var s='http://liorean.web-graphics.com/bookmarklets/bookmarklet.js',// url to load
t='text/javascript',// script type
q='\u0022',// greater than sign
d=document,// space savings
n=navigator,// dito
e;// element container
if(/mac/i.test(n.platform)&&/msie/i.test(n.userAgent)) // if ie5m, do it this way
(d.createElement('div')).innerHTML='\u003cscript type='+q+t+q+' src='+q+s+q+'\u003e\u003c/script\u003e';// write the script tag to the innerHTML of a div
else{// otherwise
(e=d.createElement('script')).src=s;// create script, set source attribute
e.type=t;// set type attribute
d.getElementsByTagName('head')[0].appendChild(e)// append it to head element
}
})();// Call the anonymous function to execute the bookmarklet
void('Coded by liorean');// and of course, the author's moral right to be acknowledged for his work

liorean
03-18-2003, 06:42 PM
Hmm, there's currently no way of calling an external script and then performing a function in the current script - the current script will continue to execute while the script is loaded asynchronously. As soon as the script is loaded - but never before the current script is finished - the imported script will run. This means you'll have to move the function calls for handling the script into the script itself, or use setInterval to see if the script is loaded by object detection on whatever you declare in the script.

Jerome
03-19-2003, 10:41 AM
Hi liorean,

Thanks for supporting me with Your code. I think there are some ideas in it which I can sertainly use to build a function.

To download a *.js file doesn't seem to be the question so much, however on the moment I don't see the link between a *.js file which is just downloaded and reading the array (no function just an array) which the file contains.

When I understand Your code (very well documented but my knowledge is limited, so say me if I am wrong ) what You achieve is the following (IEwin) simply said:

You make a <SCRIPT TYPE="text/javascript" SRC="somefile.js"></SCRIPT> and put it in the header of the document, which means the document has the disposal of the *.js file and all it contains.

Which means that when the file is loaded I can read-out the array with a simple loop.

Thanks for Your effort,
Jerome

Jerome
03-19-2003, 11:09 AM
Before I forget:

Q1.
I will put this script in an external *.js file. Do I need to write the label java script as well?

Q2.
Why doesn't it work in IE5.0 / is it possible to make it work in IE5.0 (DOM supported, not?)

Jerome

liorean
03-19-2003, 09:55 PM
I don't know - I'd have to fiddle about with the script in that browser a little to determine anything - I believe the reason I wrote ie5.5+w was that I hadn't any install of ie5w to work with at the moment, though, so it might actually work.

Oh, the "javascript:" part is there because this was written to be a bookmarklet href. If you remove all the comments, and remove all unnecessary whitespace (including newlines), you get a bookmarklet href for loading a script.

If you remove the "javascript:" label, you get the same functionality in an embedded or linked script as you get with the "javascript:" label on. In a href, however, that label works as a protocol, telling the browser that the link is a javascript link.

(Oh, and why does these forums split that into "java script:" if you don't escape the characters?)



As for the link between downloading the file and reading the array, you only have to think of this:

// This is array.js
var t=[blah,blah,blah,...];


// Your script in the html file
function doSomethingWithArray(a){
/*-whatever-*/
}
import('array.js'); // start loading file
doSomethingWithArray(t); // This will throw an error - t isn't declared yet

The reason for that, is that the array.js file won't be fully loaded by the time you run doSomethingWithArray.

Instead, you'll have to do it like this:

// This is array.js
var t=[blah,blah,blah,...];
doSomethingWithArray(t); // This won't throw an error


// Your script in the html file
function doSomethingWithArray(a){
/*-whatever-*/
}
import('array.js'); // start loading file



Hope that helps!

Jerome
03-20-2003, 11:02 AM
Hi, liorean,

Thanks very much and have a great week-end,

Jerome



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum