tags:

views:

166

answers:

3

For some reason when I set window.location.href = it opens another window.

window.location.href = 'https://MyDomain.com/Checkout/Purchase.asp';

It doesn't happen in my development environment, only production. The only only thing different that I can think of is that we are switching from http to https. If this were a straight link () it would work.

Any ideas how to get this to work correctly? The url is built with Javascript (it requires some information from the user).

A: 

Have you tried window.location.replace() instead?

Sam C
Thanks for the suggestion, but this replaces the current page with the new one, including in history. Not exactly what I want.
Brian
A: 

Browsers can be configured to behave many ways, you have no control from javascript if it opens a new window or not. BTW location.href is faster

asdf
The browser behavior that you're describing is accurate, but usually applies to whether a window opens in a new window or in a new tab. If he's using the same browser to access both his dev and production environments, then this is likely not the cause. Also, `location.href` is faster to type and that's about it. The scope chain resolution savings from removing window is trivial.
Justin Johnson
A: 

What about specifying the target?

window.open("http://asdf.com", "_self");
Justin Johnson