Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript window redirect doesn't work in chrome ((canceled) - status )

I'm trying to do a redirect using the below code:

<script  type="text/javascript">
window.location.href = "http://google.com"
</script>

FF and IE work as they should. Chrome doesn't.

The request above to http://google.com, gets a 'canceled' status in Chrome browser > Development tools > "Network".

I've tried several other functions:

location.href = url
location.replace(url)
document.location = url
location.assign(url)
window.open(url, '_self')

Same code pasted within a local html file works fine.

Below is the redirect request that it's canceled by chrome: http://pastebin.com/hD36M1RG

Any clues? Thanks

like image 255
Chris Avatar asked Dec 19 '11 19:12

Chris


People also ask

What is Cancelled status in network tab?

You did something that made loading the data unnecessary. (i.e. you started loading a iframe, then changed the src or overwrite the contents)

What is the difference between window location and location href?

window. location is an object that holds all the information about the current document location (host, href, port, protocol etc.). location. href is shorthand for window.

What is window location HREF in JavaScript?

The window.location.href property returns the URL of the current page.


2 Answers

Try without window., it helped in my case. I had used location.assign() instead of window.location.assign() and worked.

like image 58
DnT Avatar answered Oct 06 '22 23:10

DnT


I was doing the same thing. A quick patch was to add a little delay before the redirect using setTimeout.

like image 38
Mark Torres Avatar answered Oct 06 '22 23:10

Mark Torres