[thelist] Loading a file with js!

Liorean liorean at user.bip.net
Tue Feb 11 12:55:04 CST 2003


Hans Fraser wrote:
> Ok ... here it goes!
>
> what i want to do is to load the result of a php script in a layer,
> ultimately directly to a variable!
>
> I know several ways That i do not want to use!
>
> like :
> (1)loading into an iframe and then extracting the content to fill up my
> layer!
> (2)loading a .js file dynamically
>
>
> BTW: i do not care to run in ns4 and ie only solutions do not interest
> me!
> p.s.: i am not looking for a script but direction towards a solution
>     (i rather lean fishing than getting a free meal!)

The answer is, perhaps, XMLHTTPRequest, but only on ie5.5+w or moz, all
platforms. The future might allow you to do this with DOM3 LS, but for
now all ways to do it are proprietary.

See my recent post at the JavaScript Kit forums,
<http://www.codingforums.com/showthread.php?s=&threadid=14463>

As for dynamically loading scripts, ie5+m and possibly others as well
cause problems, but here there exist a more widely supported method.

You can find both of these operating together in my bookmarklets
ViewScripts and ViewStyles, which you can find at
<http://members.evolt.org/liorean/bookmarklets.html>.


Here's the general code for the script loader (working: ie5.5+w, ie5+m,
moz; untested: konq/saf, op7, ice; not working: op6-, nn4-, ie5-w, hj3,
ow, icab):
~~~~@~~~~
javascript:
   var s=<URL>,
   t='text/javascript',
   q='\u0022',
   e;
   if(/mac/i.test(navigator.platform)&&/msie/i.test(navigator.userAgent)){
     (document.createElement('div')).innerHTML='\u003cscript
type='+q+t+q+' src='+q+s+q+'\u003e\u003c/script\u003e';
   }else{
     (e=document.createElement('script')).setAttribute('src',s);
     e.setAttribute('type',t);
     document.getElementsByTagName('head')[0].appendChild(e);
   }
   void('Coded by Liorean');
~~~~#~~~~
The code should work the same if you just wrapped it in a function and
triggered that function, as it does in a href (just remove the newlines
to get it to work in a url).

See: <http://members.evolt.org/liorean/tests/bookmarklets.html>.
The old code works just as well as the new, I gathered. (Nathan Steiner
was kind enough to help testing then, they all work in above mentioned
browsers.)

--
liorean
m.e.o/liorean: <http://members.evolt.org/liorean/>
e-mail: <mailto:liorean at user.bip.net>
bookmarklets: <http://members.evolt.org/liorean/bookmarklets.html>
scripts: <http://members.evolt.org/liorean/scripts.html>




More information about the thelist mailing list