Paulo Dos Santos Paulo Dos Santos - 7 months ago 55
Javascript Question

JavaScript - splitting window.location.href returns undefined

I have the following code JavaScript:

var url = window.location.href;

var link = url.split('?link=');

link[1] = "" + link[1];
link[2] = "" + link[2];

function ad(){
window.location.href = link[1];

function ac(){[2], '_blank');

And there is a link:

<a href="javascript:ac();" onclick="ad();">ACCESS</a>

The problem is that in some computers, the split is not working.

For exemple: If the link is
It should give me
instead of

What is the problem with those computers?


Thanks, @arcyqwerty! I did what you suggested.

Usually ? is used for separating the query string from the path (see comment above). Try using another separator like link=abcd,efgh,ijkl. You can use this to get the query string variable. – @arcyqwerty

Go to the answer