My question to you would be, how are you updating the 'hidDataChanged' input field?
My code is not setting that field for you, but as long as there is an input field with the value 'Yes' then that code works as intended (the version I posted). The alert() you added is ignored in all modern browsers when fired on the onbeforeunload event.
I placed the alert in just to see if the checksave function was firing. Remember, I'm in a fixed IE11 compatibility mode environment, aka, IE 7.0. The alert pops up, so I know the CheckSave function is in fact being called.
When I change the alert to be alert(document.getElementById("hidDataChanged").value);
it alerts Yes
I have a function that changes the data to Yes onchange. However, I've tested with hard coding the value to Yes.
The return portion is not working, or stopping the code rather. Here is the code and I'll explain what happens:
if(document.getElementById("hidDataChanged").value == "Yes")
return "You have unsaved data, are you sure you wish to leave the page?";
window.onbeforeunload = function()
var $a = CheckSave();
When I simply refresh the page, it alerts 2 as the hidDataChanged does not equal yes yet.
When I make a change to data, then hit refresh, it alerts 1, then refreshes the page.
So, it sees the return portion of code, then either stops, or ignores everything else.