474,037 Members | 43,894 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.lo cation.href='ur l 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.onbefore unload = foo;

eval('window.lo cation.href=\'h ttp://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 8477
Scott Mitchell wrote:
<snip>
eval('window.lo cation.href=\'h ttp://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.javas cript 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.javas cript 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

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

Similar topics

4
10611
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 Sun's JVM. My understanding that the onbeforeunload call is a Microsoft one, and the net result of having it in a page used by a SUN JVM user is that the
6
23192
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 another way to do the same thing in Safari? (that is, intercept a request to leave the page). I tried Safari 2.02 on Tiger. Thanks!
0
1872
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 cases. However, in my testing, the onbeforeunload event is sent twice. This causes problems in certain cases where I want to suppress the "The page has changed" message, as in the case of a "Cancel" button being hit.
4
10212
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 executingPostBack = false;
8
7598
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 bunload(o){ return false; }
1
4129
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 onbeforeunload. I have the event inside the BODY element in my aspx page and it seems to work just fine. However, I still get a flash of a page error in the lower left corner of my browser and the Visual Studio 2005 "souce" page shows the event name...
6
5957
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 or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard...
1
108869
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 button anyways, if the user ventures away from your page then they wouldn't have this button at their disposal. The main reason people ask how to control or disable the back button is because they have a need to control sensitive (and/or) dynamic web...
0
10532
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10328
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
11978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11128
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10297
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8685
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7856
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6639
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3951
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.