views:

47

answers:

1

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? 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: xxx.com/products/edit/100

Url of GET: xxx.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. :)

+2  A: 

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.

Guffa
That's something I did not consider. Ok, will have a lookover the code again.
seanlinmt
+1 for correctness - though if you're screwing up `return false;`, it's time to call it a day, get coffee, come back later :)
Nick Craver
@Nick Craver: but not too much coffee, right?
Andy E
@Andy - hahaha, well played sir
Nick Craver