[ic] HOW-TO on detecting javascript

Mike Heins mike at perusion.com
Sun Oct 16 12:28:19 EDT 2005

Quoting Kevin Walsh (kevin at cursor.biz):
> Randy Just [randyjust at justcomp.com] wrote:
> > After looking at the various archives for a long period of time and
> > also analyzing
> > a recent response on this group, I am still befuddled as to good way
> > of detecting
> > if javascript is turned on or not.
> > 
> > I have set-up a kludge for users not having javascript enabled to go
> > to a non-javascript
> > checkout page from shipmode.html.  Right now I have a button in place for
> > users to click on who don't have javascript enabled.
> > 
> > Ideally, I would like to put in the code an [if] statement where if
> > an old browser is detected
> > or if javascript isn't available, the next button will automatically
> > send the user to
> > a non-javascript checkout page.
> > 
> > I am not literate with javascript and have looked at a number of
> > scripts from the archive as
> > well as testing code sets.  I don't seem to be able to set a variable
> > I can compare against
> > to go to the javascript enabled or javascript disabled paged.
> > 
> > I am looking to do something such as
> > 
> > [if old_browser or no javascript]
> >    checkout
> > [else]
> >    finalize
> > [/else]
> > [/if]
> > 
> > with the focus being how to get a javascript value in play to compare
> > against. 
> > 
> I imagine that you could add something like this to your various
> "add to basket" forms:
>     <noscript><input type="hidden" name="no_javascript" value="1"></noscript>
> Once you get to the checkout, you should be able to perform a JS test
> like this:
>     [if value no_javascript]
>         No JS available
>     [else]
>         User has JS
>     [/if]

If you want to figure it out at basket time or something, you
can do:

	[if !scratch set_browser]
	    [set set_browser]1[/set]
	    [set no_javascript]1[/set]
	<img id=testjs src="bg.gif" border=0>
		var el = document.getElementById('testjs');
		if(el != undefined)
			el.src = '[area special/setnewbrowser]';

	no_javascript=[scratch no_javascript]

Then in pages/special/setnewbrowser.html:

    [set no_javascript]0[/set]
    [deliver file="images/bg.gif"]

The first time you access the basket, you will see "old_browser=1".
The second time, you will see "old_browser=0", assuming the browser
has javascript turned on (and it is late enough to be usable with
the DOM 1.0 code of IC).

Then in your mv_click you can do:

	[if scratch no_javascript]

Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295  tollfree 800-949-1889 <mike at perusion.com>

Software axiom: Lack of speed kills.

More information about the interchange-users mailing list