Redirect according to browser type

Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
User avatar
JanMolendijk
Posts: 282
Location: Holland Rotterdam

Redirect according to browser type

Pleasant Coursesweb,

I have two `simple` javascript what I wanna combine between detecting in two different browsers to script to another page.

- Edge browser scipping to an page were I can use unlimited speech engine.

- Chrome browser scips to another basic page couse huge limits in speech engine.

I do not known mutch from javascripts, thought to solve this easely `but no`

How can I make it work ?

The timer is right, also the browser-detection works propper.

Code: Select all

location.href="index-normal.php"
Only the rederict keep going to one page (index-normal)

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var start=new Date();
	start=Date.parse(start)/1000;
	var counts1=4;
	function CountDown1(){
		var now=new Date();
		now=Date.parse(now)/1000;
		var x=parseInt(counts1-(now-start),10);
		if(document.form1){document.form1.clock1.value = x;}
		if(x>0){
			timerID=setTimeout("CountDown1()", 1000)
		}else{
			location.href="index-talk.php"
		}
	}
//  End -->
</script>

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
<!--
window.setTimeout('CountDown1()',400);
-->
</script>

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var start=new Date();
	start=Date.parse(start)/1000;
	var counts=4;
	function CountDown(){
		var now=new Date();
		now=Date.parse(now)/1000;
		var x=parseInt(counts-(now-start),10);
		if(document.form2){document.form2.clock2.value = x;}
		if(x>0){
			timerID=setTimeout("CountDown()", 100)
		}else{
			location.href="index-normal.php"
		}
	}
//  End -->
</script>

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
<!--
window.setTimeout('CountDown()',400);
-->
</script>

Code: Select all

<!doctype html>
<html>
<head>
<title>Test demo</title>
</head>
<body>
<script>
    var browser = (function (agent) {
        switch (true) {
      

            case agent.indexOf("edg") > -1: return "<FORM NAME='form1'><p align='center'>You will redericted in Edge <INPUT TYPE='text' NAME='clock1' SIZE='2' VALUE='4'>  seconden. edge </FORM> edge ";
          
            case agent.indexOf("chrome") > -1 && !!window.chrome: return "<FORM NAME='form2'><p align='center'>You will redericted in chrome <INPUT TYPE='text' NAME='clock2' SIZE='2' VALUE='10'>  seconden. chrome </FORM> chrome";
            default: return "other";
        }
    })(window.navigator.userAgent.toLowerCase());
    document.body.innerHTML =  " " + browser + " browser." + "<br>ok<br>";
</script>
</body>
</html>
All above Code is in one html-page....

MarPlo
Hello,
Try the following code; it makes a redirect to another page according to browser type: edge or chrome.

Code: Select all

<script>
function browserRedir(){
  var brt = window.navigator.userAgent.toLowerCase();
  if(brt.indexOf('edg') > -1) window.location.href ='index-talk.php';
  else if(brt.indexOf('chrome') > -1) window.location.href ='index-normal.php';
  else alert('other');
};

browserRedir();
</script>

JanMolendijk
Marplo thanks for quick feedback took me more hours, I should have come earlier with asking questions.

It is a waste I`m not have experiance with Javascript cause for hobby it can be helpfull for all kind creativity.

For this meight an short period lessons can crick my knownledge, sometimes I thinking about it. For now my life is turbulent en mashy with special dossier what I still busy to workout full negativity this makes it to hard to combi with javascript lessons.

Last period I even not motivated to make some music what I use to keep myself clean from all.

But their is sight, meight hopefully I can be completed in few years with my important file.

Coursesweb for me have more value than stackoverflow.
Even google is unable to reach for questions about Chrome browser or does not wanna answer. More tech-compangies have this attitude. Shamble issue in an modern-time this arogance will never be accepted, hope I can bring even with this issue something for all civilions to order politic.


Have a nice Sunday & thank you again for the support.

your sincerely