Home Geschichten Kunst Computer Tindertraum

[current]

JS on-/offline switcher
(Monday 8th December 2003)

What I'm trying to do:
I have a HTML page on the local (file-)system. If it get's loaded, some JS needs to decide if a (online) address is reacheable, and load that or another local page accordingly...

I'm looking for ideas of hpw to discover if a remote URL is reacheable in JavaScript... maybe by doing some kind of var rimg = new Image(remoteUrl); kind of thing...

I'm open for suggestions on this.

This seems to work ok;
<html>
<head>
<title>On-/Offline Tester </title>
<script language="JavaScript" >
        switchUrl = "file:///C:/locals/index.html";
</script>
<script src="http://remote.tld/switchUrl.js" language="JavaScript" ></script>
</head>
<body onload="location.href=switchUrl;" >
<h1>On-/Offline Tester </h1>
</body>
</htmö>

#### in the switchUrl.js ####
switchUrl = "http://remote.tld/index.html";


No, that's too easy, isn't it? the remote *.js file is CACHED by IE and others!!!

Ah, Danke Andi, so geht's:
var randNum = Math.random ();
document.write("<scr"+"ipt src=\"http://remote.tld/switchUrl.js?"+randNum"\" language=\"JavaScript\"></scri"+"pt>);


Replacing the second script tag with the static *.js URL by an dynamic' URL prevents caching nicely :) <

[ by Martin>] [permalink] [similar entries]

similar entries (vs):

similar entries (cg):

no similar entries (yet?)

Martin Spernau
© 1994-2003

traumwind icon Big things to come (TM) 30th Dez 2002

Is there something missing?
Oblique Strategies, Ed.3 Brian Eno and Peter Schmidt



amazon.de Wunschliste





 

usefull links:
Google Graph browser
Traumwind 6-Colormatch
UAV News

powered by SBELT