473,569 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way to deal with Javascript (in)compatibili ty using PHP?

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=I E" or "&browser=D OM" 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($nam e) {
if($_GET[brow] == "IE") {
return "document.all(' $name')";
}
else {
return "document.getEl ementById('$nam e')";
}
}

That we use like this (for example here we are setting the inner HTML
for the item whose ID is 'contribute'):

<?=javascript(' contribute')?>. innerHTML = "Name";

Everything was working fine but we have realised that the Googlebot
cannot deal with $_GET parameters so we are looking into url rewriting
but it is going to be very complicated to keep the method we are using
with url rewriting.

We would be interested in hearing about the way people deal with
javascript browser compatibility using PHP. There must be some much
simpler ways of doing this but we are not sure how to do it.
Any input would be helpful.

Thanks

Jul 17 '05 #1
6 2022
"ch***********@ hotmail.com" wrote:
Hi

We have started off using a $_GET parameter to keep track of the user's
browser:
Bad idea. Unless you don't really care what happens when people share links
to your site, or visit your site from search engines.
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=I E" or "&browser=D OM" at the end of the url (and we keep the
browser parameter in the URL the whole time he is on the website),
That is probably going to damage your search engine ranking.
this
enables us to use the following PHP method:

function javascript($nam e) {
if($_GET[brow] == "IE") {
return "document.all(' $name')";
}
else {
return "document.getEl ementById('$nam e')";
}
}


Has it not occurred to you that you can do all of this in Javascript?

function getObject(n) {
if (document.all) return document.all(n) ;
else return document.getEle mentById(n);
}

Here are a couple of links for you:

http://www.google.co.uk/search?q=jav...ject+detection
http://en.wikipedia.org/wiki/KISS_principle
--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/
Jul 17 '05 #2
We would be interested in hearing about the way people deal with
javascript browser compatibility using PHP. There must be some much
simpler ways of doing this but we are not sure how to do it.
Any input would be helpful.


I'm not sure to understand which is the problem with
document.getEle mentById for you (it should work on almost all present
and future browsers) but try to read this page:

http://www.metalusions.com/backstage/articles/8/
Jul 17 '05 #3
Avoid URL rewriting altogether. I think there are more problems
associated with this than you realize.

Set a $_SESSION variable. Check/set it at the beginning of every page.

session_start() ;
if (isset($_SESSIO N['browser']) == false) $_SESSION['browser'] =
yourDetectionFu nction();

This will allow the rest of your adaptive code to still work, without
constantly having to explicitly pass around something that should be
the same on every single page during a session.

~D

Jul 17 '05 #4
On 29/06/2005 13:39, Philip Ronan wrote:

[snip]
http://www.google.co.uk/search?q=jav...ject+detection


The term, object detection, probably isn't the best one to use. It has
connotations with 'Browser detection via object inference', as you might
notice by looking at some of the search results. A better phrase to
consider is feature detection, and it is this principle that the OP
should be trying to embrace.

The actual browser that is in use should normally be of absolutely /no/
concern. The only interest should be what the capabilities are of that
browser (hence /feature/ detection).

Feature detection typically involves a one-to-one analysis of the
environment. Simply assuming that because the host supports - for
instance, document.getEle mentById - that it must automatically support
the entire W3C DOM Core module is clearly flawed (though that's what
many seem to do). Instead, one determines what is necessary to perform a
particular task, and then sets about finding if those methods and
objects are indeed present in the host environment. Doing this in an
efficient manner typically requires a thorough understanding of ECMAScript.

The FAQ notes for comp.lang.javas cript gives a more in-depth treatment
of why the various detection methods are flawed, and why feature
detection is vastly superior (including some simpler examples). If you
have particular issues, post there.

See <URL:http://www.jibbering.c om/faq/faq_notes/not_browser_det ect.html>

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 17 '05 #5
ch***********@h otmail.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=I E" or "&browser=D OM" 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($nam e) {
if($_GET[brow] == "IE") {
return "document.all(' $name')";
}
else {
return "document.getEl ementById('$nam e')";
}
}


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

function ob(oname) {
if (document.getEl ementById)
return document.getEle mentById(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 )
Jul 17 '05 #6
Hello,

on 06/29/2005 09:24 AM ch***********@h otmail.com said the following:
We would be interested in hearing about the way people deal with
javascript browser compatibility using PHP. There must be some much
simpler ways of doing this but we are not sure how to do it.


Often is not a matter of dealing with browser differences but also
different Javascript versions in different versions of the same browser.

The most reliable way to solve that problem is to provide alternate
Javascript code that is conditionally executed at Javascript run time
depending on what the browser supports.

That is the solution used by this form validation class for instance to
validate e-mail addresses. If the regular expression objects are
available, it uses them, otherwise it uses a more basic type of e-mail
address validation:

http://www.phpclasses.org/formsgeneration
if(s.search)
{
return (s.search(new RegExp('email-regular-expression','gi '))>=0)
}
else
{
some other type of basic validation;
}

Regular expression detection support is made checking the existence of
the search method in the string object.

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1987
by: norton | last post by:
Hi all. I have a question in using Request and Request.Form when the asp page is Request("txtName") i can use "testpage.aspx?txtName=User1" to post the value but when i use Request.Form("txtName") i cannot use that method,
1
1495
by: Neil Morris | last post by:
Hi I was wondering if anyone knows if of javascript compatibility tables or some program that can convert the html/javascript etc to be as cross-browser as possible! thanks in advance Neil Morris -- my IE6 favorites for import into Netscape/Internet Explorer
1
1645
by: ½Éº¸ÁØ | last post by:
Hello guys. I have a problem in using a public static library. The library file name is libminipar.a and it was written in c++. For using the public library, I first wrote test.c(and test.cpp) which included following. // test.c ////////////////////////////////////////// #include "ptree.h" //library header file int main() {
6
377
by: Norton | last post by:
When i try to use OleDbDataAdapter's QueryBuilder, when i type some SQL Statement "Select Top X .....", it works and display the correct result, however i cannot generate the select statement successfully.... what can i do?
2
1149
by: shama | last post by:
HI all, I am new on .net framework, I am using .net 2005 I want to create add-in for Microsoft office, using VC++ with managed code. When I had made add-in using Extensibility project -> shared add-in with language VC++, it was not giving Common language runtime support, so I was unable to make managed code ! IF there is any solution...
6
1648
by: palani12kumar | last post by:
hi everybody... I've a problem in using system() functions. my program was: int main() { clrscr() system("dir"); getch(); }
5
3409
by: howa | last post by:
Besides 1. matter of taste 2. XHTML content-type issue, i.e. trigger IE quirk mode if send using the correct xml content type Are there any real advantage that can differentiates these two?
5
2565
by: =?Utf-8?B?Sm9obk1TeXJhc29mdA==?= | last post by:
I'm coding in VB.NET 2005 with a Using block and a StreamWriter as in Using strWrite As New IO.StreamWriter(fileName, True) strWrite.WriteLine(Now & vbTab & cLineToWrite) End Using Should I explicitly call the Close method on the StreamWriter or is the object closed and disposed when the Using block is exited? Thanks for your insights.
6
14512
by: tshad | last post by:
Can't use FileInfo in using statement? I have the following statement: using (FileInfo fInfo = new FileInfo(fromImagePath + "\\" + (string)dr)) and I get the following error: 'System.IO.FileInfo': type used in a using statement must be
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.