开发者

javascript error causes page reload?

I have been get开发者_运维问答ting some weird page refresh in deployment and I can't seem to find the cause of it or replicate it in development. Is there a way for a javascript error or exception to cause a page reload? Or some tips to help me narrow down the cause?

It happens when deployed in the field and I can't replicate it while testing locally. I know it's happening as I'm logging exceptions using ELMAH. User is using Firefox.

UrlReferrer: example.com/products/edit/100

Url of GET: example.com/products/edit/undefined

And I don't see any javascript code in the form of window.location = '/products/edit/' + id, (where id might be undefined) that could be called from that page.

But there are calls like the above elsewhere. I hope that made sense. :)


No, there is no Javascript error that by itself would cause a page to reload. There is no reason for the browser to reload the page if an error occurs, the only thing that it could hope to achieve by that is to cause the same error to happen again.

So, the only reason that a Javscript error could cause a reload is if the script is preventing a reload when it's working properly, or if it normally causes a reload in some specific situation and fails to limit it to that situation.

Example: If you have code that prevents a click from causing a postback:

<a href="page.html" onclick="return false;">

If there was an error in the script it would no longer prevent the reload.


The question has already been answered, but I wanted to add a suggestion on debugging this behaviour.

I am using Firefox / Firebug for a lot of JS development, and sometimes I will see an exception raised in Firebug right before the page submits and there's nothing I can do about it. If I have 100s of lines of JS in response to an event I don't want to step through it all looking for the 1 line that contains an error and causes a reload.

Once I can replicate the error I use Fiddler to set a breakpoint on a url (e.g. bpu localhost which will halt any requests headed for localhost. Even though the browser has submitted it still provides access to Firebug so I can inspect the error while Fiddler holds the request.

Hope this helps someone

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜