Re: Best way to deal with Javascript (in)compatibility using PHP?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Best way to deal with Javascript (in)compatibility using PHP?

From: Kenneth Downs <knode.wants.this@see.sigblock>
Date: Wed Jun 29 2005 - 17:15:07 CEST

christian9997@hotmail.com wrote:

> Hi
>
> We have started off using a $_GET parameter to keep track of the user's
> browser:
>
> We detect what browser the visitor is using when he first arrives on
> our website then we do a redirect to the same page adding on
> "&browser=IE" or "&browser=DOM" at the end of the url (and we keep the
> browser parameter in the URL the whole time he is on the website), this
> enables us to use the following PHP method:
>
> function javascript($name) {
> if($_GET[brow] == "IE") {
> return "document.all('$name')";
> }
> else {
> return "document.getElementById('$name')";
> }
> }
>

If find that putting this function into your javascript library solves the
problem:

function ob(oname) {
  if (document.getElementById)
   return document.getElementById(oname);
  else if (document.all)
   return document.all[name];
}

Once this is in there, you can write universal code that just refers to
objects using the "ob('id')" function. Note that it is going by ID, not by
name.

-- 
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
Received on Mon Oct 17 20:59:16 2005