Paulo Dos Santos Paulo Dos Santos - 1 year ago 169
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download