Well, first, it's never such a good idea to detect browsers, partially because you have to use the User-Agent which can't be trusted (as anything coming from the user). You should be sure that you need to do it. It can seem simpler to simply do different things for each browser, but it's not, and usually, you don't need to do that (except in rare occasions and for IE, because yeah the old IE...).
If you know what you're doing though, you can use window.location.replace()
coupled with a setTimeout(), like that:
setTimeout( function(){ window.location.replace("redirectionpage"); }, 8000 );
Or you could use the meta refresh, which might be more logic (and you could put it in Javascript, or even PHP if you can, which might be better). Like:
<meta http-equiv="refresh" content="8;URL='redirectionpage'" />
It would be nice if you could give more details, but that should be enough.
EDIT: How to put the meta tag depending on the browser.
So as I said in the comment, there are two solutions to add the meta tag. Add it in the HTML, then delete it for non-webkit browsers, or add it only for webkits browsers when the page is loading.
The former is pretty simple, you put the tag above in the <head>
, preferably with an id
(for easier access). For example:
<meta http-equiv="refresh" content="8;URL='redirectionpage'" id="webkit_meta" />
Then simply remove it in Javascript when the page is loading (just put it in a <script>
tag in the <head>
, after the <meta>
) with something like
var webkit_meta = document.getElementById("webkit_meta");
webkit_meta.parentNode.removeChild(webkit_meta);
Concerning the second solution, it avoids having a <meta>
tag which is going to be useless for some browsers in your HTML. You just need to create a meta
tag, set its attributes, then put it in the <head>
.
var meta = document.createElement("meta");
meta.httpEquiv = "refresh";
meta.content = "8;URL='redirectionpage'";
document.getElementsByTagName("head")[0].appendChild(meta);
For the webkit test, you can simply do if ( /webkit/i.test(navigator.userAgent) )
(to test if it's a webkit browser, add a !
if you want to test non-webkit browsers). Once again, don't forget that info can't be trusted. :)
So, to summarize, all you have to do is choose either of these methods, then put a script to either delete/add you <meta>
tag, depending on the browser.
<script type="text/javascript">
if ( /webkit/i.test(navigator.userAgent) )
{
var meta = document.createElement("meta");
meta.httpEquiv = "refresh";
meta.content = "8;URL='redirectionpage'";
document.getElementsByTagName("head")[0].appendChild(meta);
}
</script>
Or
<script type="text/javascript">
if ( !/webkit/i.test(navigator.userAgent) )
{
var webkit_meta = document.getElementById("webkit_meta");
webkit_meta.parentNode.removeChild(webkit_meta);
}
</script>
That should be enough. ^^
(yes lots of code)