Javascript error causing page reload?
I got some weird page refresh while deploying and I can't find the cause of this or reproduce it during development. Is there a way for a javascript error or exception to cause a page reload? Or some tips to help me narrow my case?
This happens when deploying to the field, and I cannot replicate it when testing locally. I know this happens when I log exceptions using ELMAH. The user is using Firefox.
UrlReferrer: example.com/products/edit/100
GET url: example.com/products/edit/undefined
And I don't see any javascript code like window.location = '/ products / edit /' + id (where id can be undefined) that can be called from this page.
But there are challenges like the one above elsewhere. Hope it made sense. :)
a source to share
No, there is no Javascript error that will cause the page to reload on its own. The browser has no reason to reload the page if an error occurs, and the only thing it can hope to achieve is to repeat the same error.
So the only reason a Javscript error can cause a reload is because the script prevents a reload when it runs correctly, or it usually causes a reload in some particular situation and cannot restrict that situation.
Example. If you have code that prevents a click from triggering a postback:
<a href="page.html" onclick="return false;">
If there was an error in the script, it wouldn't have prevented a reload.
a source to share
The question has already been answered, but I wanted to add a suggestion for debugging this behavior.
I am using Firefox / Firebug for a lot of JS development and sometimes I see an exception being raised in Firebug right before the page is submitted and I can't do anything about it. If I have 100 lines of JS lines in response to an event, I don't want to go through it, everyone is looking for 1 line that contains an error and causes a reload.
As soon as I can replicate the error, I use Fiddler to set a breakpoint on the URL (for example, bpu localhost
which will stop any requests routed to localhost. Even though the browser sent it, it still exposes Firebug so that I could check while Fiddler contains the request.
Hope this helps someone
a source to share