after prompting I got "unspecified error"

S

sowencheung

I have the following code in the event onbeforeunload

if ( typeof executingPostBack != 'undefined' && !executingPostBack )
event.returnValue = ""Warning: Modified data has not been saved."";

executingPostBack is a global variable.

I have another function for another event trying to access an object as
follows:

window.location.href = targetObj.href;

everything is OK, but it raises the "unspecified error" when I click
cancel in the popup confirmation window.

anyone gets experience of this ?

thank you very much!
 
T

Thomas 'PointedEars' Lahn

I have the following code in the event onbeforeunload

if ( typeof executingPostBack != 'undefined' && !executingPostBack )
event.returnValue = ""Warning: Modified data has not been saved."";
^^ ^^
String literals are to be delimited by only one <"> or <'> character.


PointedEars
 
V

VK

I have the following code in the event onbeforeunload

if ( typeof executingPostBack != 'undefined' && !executingPostBack )
event.returnValue = ""Warning: Modified data has not been saved."";

executingPostBack is a global variable.

I have another function for another event trying to access an object as
follows:

window.location.href = targetObj.href;

everything is OK, but it raises the "unspecified error" when I click
cancel in the popup confirmation window.

Not me: by my observations onbeforeupload handler works smoothly.
"Unspecified error" usually meand that you managed to twist the engine
totally for all 360deg, so it doesn't remember its name and the year
anymore :)

This line make me suspitious:
window.location.href = targetObj.href;
-not by itself but because you call it "access an object". You are not
accessing an object, you are navigating away from the current page to
the targetObj.href location. If you have onbeforeunload confirmation
already pending for user interaction, add some more pending events...
add a bit of fantasy... I guess it is possible to produce "Unspecified
error". :)

Could you narrow you problem to some minimum (but self-contained) code?
 
S

sowencheung

ooops~

sorry, that's a typo
ignore that, 'cause i am using some code-behind to output the script
 
S

sowencheung

thanks for your reply. but why if I click [OK] in the confirmation
window, everything works fine?

my code actually tends to do some hotkey stuffs:

I creates several functions for my links, for example:

function fndnn_ctr407_RelatedData_PageNav_CancelButtonKeyup(event)
{
var b =
document.getElementById('dnn_ctr407_RelatedData_PageNav_CancelButton');
Hotkey(event, b, false, false, true, 67);
}
if (document.addEventListener)
document.addEventListener('keyup',
fndnn_ctr407_RelatedData_PageNav_CancelButtonKeyup, true);
else
document.attachEvent('onkeyup',
fndnn_ctr407_RelatedData_PageNav_CancelButtonKeyup);

there are several other functions, ie. for Save button, etc.

they are all attached to the onkeyup event, and I also have an event
for onbeforeunload.

my hotkey function is as follows:

function Hotkey(event, targetObj, ctrlKey, shiftKey, altKey, keycode)
{
if (processing) return;

processing = true;

if (
targetObj
&& event.ctrlKey == ctrlKey
&& event.shiftKey == shiftKey
&& event.altKey == altKey
&& event.keyCode == keycode
)
{


// if we need to post back
if (targetObj.href && targetObj.href.indexOf('doPostBack')>0)
{
executingPostBack = true;
window.location.href = targetObj.href;
}
else if (targetObj.onclick)
{
targetObj.click();
}
else
{
window.location.href = targetObj.href;
}

}

processing = false;
}

When the user clicks [Add] button, I assumes the page is modified, then
I register the onbeforeunload event to prompt the user.
Everything works fine, but it fails when the user clicks [Cancel] in
the confirmation window. The error happens at that line trying to
access targetObj.

any idea?

Thanks
 
S

sowencheung

HaHa!

it works

after I use this :

var url = targetObj.href;
try
{
window.location.href = url;
}
catch (e)
{
// do nothing
}
 
T

Thomas 'PointedEars' Lahn

it works

after I use this :

var url = targetObj.href;
try
{
window.location.href = url;
}
catch (e)
{
// do nothing
}

Note that this will break in IE < 5.0. Maybe you are looking for

window.location = url;

instead.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top