473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

onbeforeunload and eval Problems in IE

I am using the onbeforeunload client-side event to prompt a user when
leaving a page after they have made changes, as discussed in this
article: Using ASP.NET to Prompt a User to Save When Leaving a Page
[http://aspnet.4guysfromrolla.com/art...101304-1.aspx]. The problem
I am having is with the page unloading via eval. Specifically, I am
using telerik r.a.d. menu
[http://telerik.com/Default.aspx?PageId=1415], which redirects users to
another page via script like:

eval('window.location.href='url of menu item');

When a user attempts to leave the page via a menu option, they get the
prompt, as expected, but if they click Cancel there is a script error:
Unspecified error on the line number of the eval() function call. This
works just fine in Firefox.

I created a VERY simple page to test this out and confirm that it is
the eval() function. The page below, when visited through IE, displays
the prompt and if I click Cancel I get the same Unspecified error.

<script>
function foo()
{
return "bar";
}

window.onbeforeunload = foo;

eval('window.location.href=\'http://www.google.com\'');
</script>

I was unable to find any info via Google as to if this is a well-known
bug or if there are any workarounds. Any ideas/suggestions/comments
most appreciated. (I'm posting this in the telerik forums as well;
hopefully there's an easy way to get rid of those eval() statements,
but I doubt it... )

TIA

Jul 23 '05 #1
12 8419
Scott Mitchell wrote:
<snip>
eval('window.location.href=\'http://www.google.com\'');
</script> <snip> hopefully there's an easy way to get rid of those eval()
statements, but I doubt it... )


No, its easy to get rid of that - eval - call. You just remove it:-

window.location.href = 'http://www.google.com';

Richard.
Jul 23 '05 #2
The eval statement is embedded in the logic for a particular ASP.NET
Web control (telerik's r.a.d. menu). Removing the eval() is not as
simple as you make out. Basically there is a JavaScript function in
the script library for r.a.d. menu that does an eval of what is passed
in, and that particular command - window.location.href... - might be
passed in, depending on a variety of menu settings and so forth.

Jul 23 '05 #3
Scott Mitchell wrote:
The eval statement is embedded in the logic for a particular ASP.NET
Web control (telerik's r.a.d. menu). Removing the eval() is not as
simple as you make out. Basically there is a JavaScript function in
the script library for r.a.d. menu that does an eval of what is passed
in, and that particular command - window.location.href... - might be
passed in, depending on a variety of menu settings and so forth.


Then get a better menu system.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #4
So are you saying that onbeforeunload and eval are not compatible with
IE and there's not a known workaround?

Getting a new menu control is probably the last option since, (a)
Money's been dropped on this one, and (b) The menu control is working
great except for this issue on a very large site. Replacing it would
no doubt take considerable time and effort, so I'd like to exhaust this
avenue first.

Jul 23 '05 #5
Scott Mitchell wrote:
So are you saying that onbeforeunload and eval are not
compatible with IE and there's not a known workaround?

<snip>

One of the reasons that competent javascript authors do not use the -
eval - function (except under the most rare and extreme circumstances)
is that it obscures errors. If you just remove it and re-try the code
you may get additional insight into the cause of the problem.

Richard.
Jul 23 '05 #6
I think the *precise* cause of the onbeforeunload error is because the
script that's unloading the document occurs in the eval(). That is, in
the script sample code I sent that causes a problem, if I move the
window.location.href out of the eval(), everything works as expected.

So I believe that I have identified what, precisely, is the root cause
of this problem. I am wondering if there's a known workaround, though,
so I don't have to go through the complete hassle of retooling my site
to use a different menu component.

(I've also asked this question on telerik's support forums, so
hopefully they'll have some suggestions/insight there...)

Jul 23 '05 #7
Scott Mitchell wrote:
I think the *precise* cause of the onbeforeunload error is because the
script that's unloading the document occurs in the eval(). That is, in
the script sample code I sent that causes a problem, if I move the
window.location.href out of the eval(), everything works as expected.

So I believe that I have identified what, precisely, is the root cause
of this problem. I am wondering if there's a known workaround, though,
so I don't have to go through the complete hassle of retooling my site
to use a different menu component.


The "workaround" was given to you. Remove the eval, "everything works as
expected", and everybody is happy.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #8
Randy, is that the only workaround? As I explained earlier, that is
not a viable option. Are there any other workarounds you know of? Can
you (or someone else) point me to a URL that explains this
onbeforeunload and eval() problem in IE in more detail?

Thanks.

Jul 23 '05 #9
Scott Mitchell wrote:
Randy, is that the only workaround? As I explained earlier,
that is not a viable option. Are there any other workarounds
you know of? Can you (or someone else) point me to a URL that
explains this onbeforeunload and eval() problem in IE in
more detail?


When I tested your code last night removing the - eval - function
resulted in code that exhibited exactly the same behaviour and threw
exactly the same exceptions. Which suggests that there is no
incompatibility problem with the use of - eval - in this context, and so
there can be no work around for its use.

Richard.
Jul 23 '05 #10
I have to admit that this is probably the least useful newsgroup I've
posted to. Good thing I don't do client-side development for a living.

Anywho, a workaround to this problem was to place the eval() statements
in try{}catch{} blocks, which would suppress the JavaScript error.

Jul 23 '05 #11
(posted from ie6.browser on msnews; I don't have access to USENET
but am leaving the cross-posting as is in case it propagates)

"Scott Mitchell" <sc**************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I think the *precise* cause of the onbeforeunload error is because the
script that's unloading the document occurs in the eval(). That is, in
the script sample code I sent that causes a problem, if I move the
window.location.href out of the eval(), everything works as expected.

So I believe that I have identified what, precisely, is the root cause
of this problem. I am wondering if there's a known workaround, though,
so I don't have to go through the complete hassle of retooling my site
to use a different menu component.

Scott,

ie6.browser is not a good newsgroup for discussing developer
issues such as this. I would try one of the MSDN newsgroups
which specialize in web development or scripting.

http://msdn.microsoft.com/newsgroups/
HTH

Robert Aldwinckle
---


(I've also asked this question on telerik's support forums, so
hopefully they'll have some suggestions/insight there...)


Jul 23 '05 #12
Scott Mitchell wrote:
I have to admit that this is probably the least useful newsgroup I've
posted to. Good thing I don't do client-side development for a living.

Anywho, a workaround to this problem was to place the eval() statements
in try{}catch{} blocks, which would suppress the JavaScript error.


Your incompetence and lack of courtesy has clouded your judgement
which resulted in curing the symptoms rather than the illness. If
I would have more time, I would pity you.
PointedEars
Jul 23 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lltaylor | last post by:
Hello, Currently I use an onbeforeunload method, to do call various tidy up methods when a user exits my web application - however I now need to add additional support, for users migrating to...
6
by: jennyw | last post by:
Hi, I'd like to use onbeforeunload to submit a form before leaving a page. This works in Firefox and IE. Safari, however, blithely ignores this. Does anyone know of a workaround for Safari? Or...
0
by: Rick Lubanovic | last post by:
I have been working on a script to check if a page has changed before the user leaves the page. I have a call to a javascript function on the onbeforeunload event. This seems to work in most...
4
by: sowencheung | last post by:
the bug of onbeforeunload is so obvious! in IE 6 it will popup twice "sometimes" I am using the following code window.onbeforeunload = null; window.onbeforeunload = confirmExit; var...
8
by: drewmania001 | last post by:
im currently using the following to prompt the user before navigating away from the page // add an unload event window.onbeforeunload = bunload; // function to prompt user function...
1
by: David | last post by:
I am using a process to warn users when they leave a page that there have been changes made. I took the example directly from Microsoft example I found in searching for help on the event...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
1
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.