PDA

View Full Version : Newbie code question



Inferno986
Mar 18th, 2007, 12:09 PM
Hi,

My knowledge of JavaScript is very basic. I was wondering if anyone could explain what this means:

var rightedge=isIE? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX

Its the "isIE?" and ":" that confused me. To help you out the "isIE" var returns a true value if the browser is IE.

Philip M
Mar 18th, 2007, 03:24 PM
Hi,

My knowledge of JavaScript is very basic. I was wondering if anyone could explain what this means:

var rightedge=isIE? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX

Its the "isIE?" and ":" that confused me. To help you out the "isIE" var returns a true value if the browser is IE.

It means if the browser is detected as IE then execute the instruction
var rightedge=document.body.clientWidth-event.clientX
otherwise execute the instruction
var rightedge=window.innerWidth-e.clientX

In other words, a cross-browser formulation.

Madis
Mar 18th, 2007, 03:26 PM
http://www.w3schools.com/js/js_operators.asp - in the end ... Conditional Operator

If you already read that (http://codingforums.com/showthread.php?t=2090), then your topic title was one of the bad examples.