Get url from next page with javascript

1

I'm trying to compare the next page using history.go (), ie comparing the next page with a given url to get a positive result.

SEE:     

function a() {
    if (history.go(2) == "http://www.google.com.br") {
        alert("ok");
    }
}
</script>
<button onclick="a()">verificar</button>

But nothing happens!

Another interesting thing would be if you could display the following url, with:

alert(history.go(2))

or

alert(history.forward())

But the result you get is undefined.

Or check if a URL is in history:

if (window.history.go("http://www.google.com.br")== true){
    alert("ok");
}

Or even check if there is a next page in history, such as:

if (history.forward() == true){
    alert("ok")
}

If anyone can help me, thank you in advance.

    
asked by anonymous 14.12.2014 / 13:56

1 answer

2

The methods history.go , history.back and history.forward have no return value. The purpose of these methods is to navigate the page history, not to know what that history is.

If you could read the history of the pages as you intended, this would be a security flaw so that malicious code could take advantage of this to find out which pages the user has accessed and then send this information to some malicious website, and therefore violating the user's privacy.

I recommend that you do server-side crawling of pages that the user has accessed on your site. This will give you the relevant history portion for your site and you can redirect it as needed using history.go(url) .

    
14.12.2014 / 14:41