window.location.href = window.location.href and JSLint

Viewed 13815

If using

window.location.href = window.location.href;

to reload a page (without re-POSTing) is not bad practice, what should we make of JSLint's "Weird assignment" complaint?

EDIT window.location.reload() is not suitable when you don't want to POST the form data again. In some browsers it provokes the "Resend form data?" which is best avoided when not needed.

UPDATE I did some very brief testing and found:

  • Chrome 12 and Safari 5.0.5 on Mac do not re-POST with .reload()
  • FF 2.0, 3.6, 4.0, 5.0 on Mac present the user with the "resend form dialog" with .reload(), .reload(true), and .reload(false)
  • IE6, IE8(standards), IE8(IE7 mode,standards) in XP; and IE9 and IE10-tech-preview in Win7 behave the same as FF on Mac
  • window.location = window.location.href works the same as window.location.href = window.location.href in all these browsers.

Here's the test script.

3 Answers
Related