Script location in a conditional block

Hi everyone
Just a quick question I want wrap a script src in a conditional block in the head and I cant work it out!!

So as an example… I want to pull in a script, only if there is an internet connection. Otherwise I want the html page to resort to a local version of the script… so I am guessing something like:

if internet connection is true
script src=“http://www.remotescript.js
else
script src=“localscript.js”

does any one know how to sniff out if there is an internet connection? or is it better if it tried the first address first, then if that doesn’t work use the next address? or I suppose some sort of time-out method which would kick in if it didn’t pull in the script after a certain amount of time…
Any way I am just not sure what’s the best approach or even how to tackle it.

cheers for any pointers max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Max,
There is nothing specifically that will allow you to check the
existence of an internet connection at a script level although you
could do this in one of two ways that come to mind.
The first is simply to load your local script and then attempt to load
the remote script over the top of this with extended functions of the
same name. If the remote script loads then you’ll have access to the
extended functionality. If not then the page will use the limited
functionality of the local code.
Another possible solution would be to attempt to load a remotely
hosted image (a 1x1 clear gif should do it) and fire a function on the
image’s onload event. If the image loads the onload event should fire
and conversely if it fails then you should get an onerror event
getting fired.
For example; http://javascript.internet.com/page-details/image-load.html
You can use successful onload event to load your remote script.
My only concern with all of this is that for those still using dial-up
(it still happens) both methods will attempt to make a connection and
will almost certainly bring the modem to life.
Regards,
Tim.

On 20 Aug 2009, at 17:14, max wrote:

Hi everyone
Just a quick question I want wrap a script src in a conditional
block in the head and I cant work it out!!

So as an example… I want to pull in a script, only if there is an
internet connection. Otherwise I want the html page to resort to a
local version of the script… so I am guessing something like:

if internet connection is true
script src=“http://www.remotescript.js
else
script src=“localscript.js”

does any one know how to sniff out if there is an internet
connection? or is it better if it tried the first address first,
then if that doesn’t work use the next address? or I suppose some
sort of time-out method which would kick in if it didn’t pull in the
script after a certain amount of time…
Any way I am just not sure what’s the best approach or even how to
tackle it.

cheers for any pointers max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

FreewayActions.com - Freeware and shareware actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks tim
for the links and advise
all the best Max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options