0

As far as I've tested, these two methods work, but I don't know which one is the best, or the differences between them, and that's what I'd like to know.

Here are the two methods:

window.location = 'http://www.google.com';
window.location.assign = 'http://www.google.com';
0

3 Answers 3

1

These two methods are equivalent. The first one is clearer to me. The syntax for assign would actually be:

window.location.assign('http://www.google.com');

Sign up to request clarification or add additional context in comments.

1 Comment

They appear to have the same behaviour and there is one clear difference-- access to history.
1

.assign() is actually a function.

The first is probably the most common.

Comments

1

The difference is this:

window.location ='' /window.location.replace(''), replaces the current document in the browser and browser history

window.location.assign('') assigns a new document to the browser and history.

Effectively "replace" does not support returning to the previous view in history (potentially useful in some applications). "Assign" allows access to history.

Difference between window.location.assign() and window.location.replace()

Comments

Your Answer

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.