0

I require the expertise of an experienced coder for a moment to help solve this issue that I am unable to solve as my skill and knowledge is basic at this current time.

Below is a script that I use in conjunction with a page creation service that in a nutshell will pass email address data from one web form on Page A and pass the email address on to a web form on Page B.

<script>
var queryDict = {};
location.search.substr(1).split("&").forEach(function(item) {
queryDict[item.split("=")[0]] = item.split("=")[1];
});

var dest = "http://google.com"; // <==== Second     Squeeze Page URL Here;

if (queryDict.email === undefined) {

var redirectURL = dest;

} else {
var redirectURL = dest + "?email=" + queryDict.email;
}

document.location = redirectURL;
</script>

I have a seperate script that detects if a user is on Chrome and redirects to URL XYZ:

<script type="text/javascript">
 if (navigator.userAgent.indexOf('Chrome') !=-1)
 {
    // Using Chrome
window.location = "http://hotmail.com"
}
</script>

I have tried on my own to combine and attempt to write new code adding on to script #1 to no avail as it is beyond my knowledge capacity at this current time.

I am unsure of how I can combine the two together so I have a script that works as intended as described below.

I would like for this script to now also detect Chrome browser users and if user "is" a Chrome user, the script is to then redirect Chrome users to XYZ URL where 'XYZ' is a destination URL I specify but at the same time still pass email address data on to a web form that will be on 'XYZ' URL whilst all other browser users will be redirect to the default URL specified in code #1, in this instance, would be 'http://google.com'.

I am very Novice with this, again, I am sure this is an easy fix for any experienced coder, I'm still learning.

Thank you in advance your help community, I look forward to receiving a solution and learning and acquiring a better understanding in the process.

C. Doe
  • 1
  • 1
  • It’s not clear what you’re asking here. You mention you’re using PHP, but there is no PHP code. You also mention that you want it to detect if a user is using Chrome, but I can’t see anything that you’ve tried to get it to work. Take a look at [JavaScript: How to find out if the user browser is Chrome?](http://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome). – Zoe Edwards Mar 11 '17 at 00:04
  • @ThomasEdwards I have updated my question accordingly to provide as much detailed information as possible. Thank you for advising me. – C. Doe Mar 11 '17 at 00:13
  • I’ve made an attempt at an answer, but this isn’t strictly a programming problem so you may be find that this get closed – but I hope this helps. I would also avoid trying to detect if a user is using a specific browser – I would say it is bad practice. – Zoe Edwards Mar 11 '17 at 00:18

1 Answers1

0

It would be something like this:

<script>
var queryDict = {};
location.search.substr(1).split("&").forEach(function(item) {
    queryDict[item.split("=")[0]] = item.split("=")[1];
});

var destination = "http://google.com";

if (navigator.userAgent.indexOf('Chrome') !=-1) {
    // Using Chrome
    destination = "http://hotmail.com";
}

if (queryDict.email === undefined) {
    var redirectURL = destination;
} else {
    var redirectURL = destination + "?email=" + queryDict.email;
}

document.location = redirectURL;
</script>
Zoe Edwards
  • 12,999
  • 3
  • 24
  • 43