Marc Davis
asked on
windows.onbeforeunload not consistently firing...
Hi all,
I have a question that maybe I'm missing something.
I have a masterpage and in it I have a window.onbeforeunload={som e confirmation function}.
Then in the content page I have a window.onbeforeunload={som e other confirmation function};
Now, the problem I am having is consistency; in some cases I can repeatedly get the confirmation information and in some cases (only data differences) I do not get the prompt.
I even changed it to something like this: window.onbeforeunload = alert('firing');confirmExi t;
On the situations cases where I do not get the prompt I obviously do not get the alert and otherwise I do.
The fact of not getting the alert indicates that it is not firing. What would cause something like that?
Just an FYI--> I am using something very similar to this: http://aspnet.4guysfromrolla.com/articles/101304-1.aspx
Any information would be greatly appreciated.
I have a question that maybe I'm missing something.
I have a masterpage and in it I have a window.onbeforeunload={som
Then in the content page I have a window.onbeforeunload={som
Now, the problem I am having is consistency; in some cases I can repeatedly get the confirmation information and in some cases (only data differences) I do not get the prompt.
I even changed it to something like this: window.onbeforeunload = alert('firing');confirmExi
On the situations cases where I do not get the prompt I obviously do not get the alert and otherwise I do.
The fact of not getting the alert indicates that it is not firing. What would cause something like that?
Just an FYI--> I am using something very similar to this: http://aspnet.4guysfromrolla.com/articles/101304-1.aspx
Any information would be greatly appreciated.
you may have a bug and at this moment javascript stop to run.
usefull page about onbeforeunload : http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript
usefull page about onbeforeunload : http://www.hunlock.com/blogs/Mastering_The_Back_Button_With_Javascript
ASKER
leakim971,
I think you're ok track with that because I did note I have a javascript error. But that javascript error is on that one that I can repeatedly reproduce that the change awareness box is not present.
The web page rendering is the same. I'm not sure what would trigger the error through.
The error is coming from this snippet of code that is injected:
"<script language=""JavaScript"">as signInitia lValuesFor MonitorCha nges();</s cript>")
On the records where it is not doing the change awareness I am getting an error on that line that indicates an invalid object name.
Any thoughts on that?
I think you're ok track with that because I did note I have a javascript error. But that javascript error is on that one that I can repeatedly reproduce that the change awareness box is not present.
The web page rendering is the same. I'm not sure what would trigger the error through.
The error is coming from this snippet of code that is injected:
"<script language=""JavaScript"">as
On the records where it is not doing the change awareness I am getting an error on that line that indicates an invalid object name.
Any thoughts on that?
we need to open box of assignInitialValuesForMoni torChanges
else to be sure a "stupid" (fast?) resolution :
(by this way you will be able to see what miss in your page or its processing)
else to be sure a "stupid" (fast?) resolution :
(by this way you will be able to see what miss in your page or its processing)
<script language=""JavaScript"">
try {
// we don't worry about error(s) caused by
assignInitialValuesForMonitorChanges();
}
catch(e) {
}
</script>
ASKER
Hmmm...I'm not sure I'm following on that because if it abends it will hit the catch block and do nothing. But the assignInitialValuesforMont iorChanges () is essential in the effectiveness of capturing the changes.
I will try it through - but I won't be able to until tomorrow A.M.
I will try it through - but I won't be able to until tomorrow A.M.
So if possible provide code of assignInitialValuesforMont iorChanges () or better a live link
ASKER
I did. It's in the OP. It's: http://aspnet.4guysfromrolla.com/articles/101304-1.aspx
I need to reproduce the bug
@Ben: It is
window.onbeforeunload=func tion() {
if (somereasontoalert) return "You will lose your data"
}
window.onbeforeunload=func
if (somereasontoalert) return "You will lose your data"
}
@mplungjan : you're right, my mistake.
ASKER
Ok, found the culprit. I'm not too sure how to get around this though. I'm not too sure if I should provide the points for this question and then open another. They are in a way related so I'm not too sure.
Here is the situation:
I did a costimation to the linked code providing in the OP (Original Post). The customization is that I took the original state values which were in a session variable and assigned them to a java script variable and then did the code injection:
strScript.AppendLine(" var arrOrig='" + Session["origState"] + "';");
strScript.AppendLine(" monitorChangesValues=arrOr ig.split(' ~');");
Now, one of the fields in the arrOrig a list of text. Everything is working fine EXCEPT when a there is a carriage return life feed in the text. When that happens the arrOrig is choking in a sense because the closing "';" is not being recognized in the var statement. So, that is throwing an issue which is further causing the other error that this question is about. (this is how it's related.)
Now, my question is HOW would/could I work with a field having a carriage return line feed (basically a \r\n) to put able successfully put into that arrOrig array?
Hopefully, this makes some sense.
Here is the situation:
I did a costimation to the linked code providing in the OP (Original Post). The customization is that I took the original state values which were in a session variable and assigned them to a java script variable and then did the code injection:
strScript.AppendLine(" var arrOrig='" + Session["origState"] + "';");
strScript.AppendLine(" monitorChangesValues=arrOr
Now, one of the fields in the arrOrig a list of text. Everything is working fine EXCEPT when a there is a carriage return life feed in the text. When that happens the arrOrig is choking in a sense because the closing "';" is not being recognized in the var statement. So, that is throwing an issue which is further causing the other error that this question is about. (this is how it's related.)
Now, my question is HOW would/could I work with a field having a carriage return line feed (basically a \r\n) to put able successfully put into that arrOrig array?
Hopefully, this makes some sense.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cool. The only difference is that I got about it by when I loaded the array I put a .Text.Replace("\r\n","@RET URN") so I knew where was at. I suppose I could've done the same with:
strScript.AppendLine("var arrOrig='" + Session["origState"].repla ce(/\\n\\r /g,"@RETUR N") + "';");
Works both ways. Either way, it worked out.
Thanks!
strScript.AppendLine("var arrOrig='" + Session["origState"].repla
Works both ways. Either way, it worked out.
Thanks!
ASKER
Actually, other way around:
.replace(/\\r\\n/g,"@RETUR N"
Carriage control line feed not line feed carriage control. :-)
.replace(/\\r\\n/g,"@RETUR
Carriage control line feed not line feed carriage control. :-)
You're welcome! Thanks for the points! Have a nice week-end!
/\\n|\\r/g should replace \n OR \r (mean any order, and the g added to the regex for any occurence as you know)
more info here : http://en.wikipedia.org/wiki/Regular_expression
(look for The choice)
more info here : http://en.wikipedia.org/wiki/Regular_expression
(look for The choice)
ASKER
Yeah...good point. I'm just used to seeming them together.
Cool call though and thanks!!
Cool call though and thanks!!
I seem to remember that it works that way.
Ben