Hello everyone. I'm an expert html5/css3 designer, but when it comes to javascript, I don't know anything...

I need some javascript code that detects a browser engine (webkit, gecko, etc.) and redirects based on that.

I need webkit and gecko to redirect to home.php and all others to redirect to basic.php.

I know people are going to tell me that if I was a good designer, I would design for all browsers/engines, and I agree. But I need this code for something completely un-related to design.

Thanks a lot in advance!

You'll find the name of the browser's layout engine is typically included in the user-agent string. Using Javascript you can access this through the navigator object. See: navigator.userAgent

To redirect to another URI you can set window.location...

So, your code might look something a little like this:

<script type="text/javascript">
    if (navigator.userAgent.indexOf('Gecko') > 0)
        window.location = "http://www.example.com";
</script>

Be aware it is possible for the user agent string to be faked. If your browser detection needs to be more resilient then you may want to research 'browser sniffing'.

It's likely there are already scripts that will do this for you and freely available to use. Unfortunately I don't have one to suggest at this time. Apologies.

Thank you very much.
I did not need the entire script to be written for me. I just needed an outline.
This will do.

Thanks again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.