简体   繁体   English

javascript错误导致页面重新加载?

[英]javascript error causes page reload?

I have been getting 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? 有没有一种JavaScript错误或异常导致页面重新加载的方法? 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. 我知道这正在发生,因为我正在使用ELMAH记录异常。 User is using Firefox. 用户正在使用Firefox。

UrlReferrer: example.com/products/edit/100 UrlReferrer:example.com/products/edit/100

Url of GET: example.com/products/edit/undefined 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. 而且我没有看到可以从该页面调用的window.location ='/ products / edit /'+ id形式的任何JavaScript代码(其中id可能未定义)。

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. 不,没有任何Javascript错误会导致页面重新加载。 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. 因此,Javscript错误可能导致重新加载的唯一原因是该脚本在正常工作时阻止了重新加载,或者在某些特定情况下通常导致重新加载并且无法将其限制在那种情况下。

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. 我正在使用Firefox / Firebug进行大量的JS开发,有时在页面提交之前,有时会在Firebug中看到一个异常,对此我无能为力。 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. 如果我有100行JS来响应一个事件,那么我不想单步执行所有操作,寻找包含错误并导致重新加载的1行。

Once I can replicate the error I use Fiddler to set a breakpoint on a url (eg 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. 一旦我能够复制错误,就可以使用Fiddler在URL上设置一个断点(例如bpu localhost ,它将终止所有前往localhost的请求。即使浏览器已提交,它仍然提供对Firebug的访问权限,因此我可以在Fiddler按住时检查错误请求。

Hope this helps someone 希望这可以帮助某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM