1

Hey guys, I have this quite simple script which works great on chrome & firefox. The idea is to nab "choice" value from the URL and proceed with the script. As mentioned other browsers work fine, but IE seems to have trouble with it.

Does anyone know a workaround? I don't want to just run the function on the previous page.

var url1 = "https://www.youtube.com";
var url2 = "http://ign.com";



function jukebox()

{

let params = (new URL(document.location)).searchParams;
let choice = params.get("choice");


      if ( choice == 1 )
     {        

               window.location=(url1);   

     }

       else if ( choice == 2 ) 
            {


               window.location=(url2);

            }

} 


jukebox();
redirect();
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964

1 Answers1

1

IE does not support searchParams but you could try writing your own parse function:

var params = {};
var str = document.location;
var start = str.indexOf("?");
document.write(start+"<br>")
start += str.slice(start).indexOf("choice=") + 7;
var end = start + str.slice(start).indexOf("&") + 1;
if (!end) end = str.length 
var choice = str.slice(start, end);
Ethan
  • 301
  • 1
  • 9