473,698 Members | 2,554 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 2028
"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
1994
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
1500
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
1650
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
1150
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 for that please suggest me... Thanks, Shyam
6
1653
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
3413
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
2570
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
14539
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
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3053
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
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.