0

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).

asked Nov 5, 2009 at 3:29

3 Answers 3

1

What about specifying the target?

window.open("http://asdf.com", "_self");
answered Nov 5, 2009 at 3:47
Sign up to request clarification or add additional context in comments.

Comments

1

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

answered Nov 5, 2009 at 3:37

1 Comment

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.
0

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

answered Nov 5, 2009 at 3:36

1 Comment

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.