473,372 Members | 1,155 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,372 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 8418
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.