Vikram Rao
Vikram Rao

Reputation: 1078

PHP / jQuery : Loading browser specific page

UPDATE:

The issue is that I am using a lot of Javascript & CSS3 enabled modules which also contain a lot of heavy javascript and images. If it is IE6 to 8 and in some cases even 9, I dont want to display those modules or display them using someother method. Using CSS property display:none or conditional stylesheets using Conditional Comments is not solving my problem as the page still remains heavy loading all the javascript and images.

Hiding them is not the resolution.

Hence I want to load a very diferrent layout with a very diferrent <div> and module position structure.

and that is why I want to load all together a diferrent page.

Kindly help with some code snippets.


I am a newbie at programming and need help. The issue is like this:

I have developed a template for my site and I am using many jQuery and CSS3 functions in it.

Obviously I am having challenges specially with IE. Hence I am seeking help in serving a browser specific page. What I want to do is:

  1. Identify the browser and IF it is IE then it loads a variable page called ie.php similarly for iphone, chrome, safari, firefox and so on.

  2. It will be great if you cansuggest me a php solution, However i am also using jQuery hence if there is a simpler and shoter method in jQuery even that is fine.

PLEASE NOTE : I am a very novice at programming, hence please help explaining a bit about the functions.

Upvotes: 1

Views: 255

Answers (5)

hobbes3
hobbes3

Reputation: 30218

Well jQuery (and JavaScript) can easily check browsers. Check out jQuery.browser.

Then once you detect the browser, you can load ie.php (I don't know why you need to) with a simple include_once() function.

Upvotes: 1

laurens peeters
laurens peeters

Reputation: 555

Since you are searching for a php-solution:

A simple switch case will do. (Or "if, else if,...")

Check for the users browser using the php get_browser function

Then, redirect the user to the correct page using header.location

Hope this helps...

Upvotes: 0

MFix
MFix

Reputation: 229

You should rather detect by feature not by browser. For this I recommend: Modernizr

For dealing with IE you will find useful Conditional comments - there is no need to use server side programming (and different template files) or JavaScript (may not be available).

Upvotes: 1

Manatok
Manatok

Reputation: 5706

If you want to load different css/js files if the browser you can put something like this in the <head> to only pull in the desired css/js

<!--[if IE 8]>
        <script type='text/javascript' src='js/excanvas.js'></script>
        <link rel="stylesheet" href="css/IEfix.css" type="text/css" media="screen" />
<![endif]-->

<!--[if IE 7]>
        <script type='text/javascript' src='js/excanvas.js'></script>
        <link rel="stylesheet" href="css/IEfix.css" type="text/css" media="screen" />
<![endif]-->

alternatively you can look at the $_SERVER['HTTP_USER_AGENT'] in PHP and see what comes through for the various browsers.

hope this helps

Upvotes: 1

Manse
Manse

Reputation: 38147

I would suggest you read up about conditional comments

you can then do (as an example) :

<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->

Upvotes: 0

Related Questions