Parent's onbeforeunload raised in IE when maximizing/minimizing a window

3 posts, 0 answers
  1. Mike
    Mike avatar
    4 posts
    Member since:
    Oct 2007

    Posted 13 Oct 2010 Link to this post

    I am currently using ASP.NET AJAX v.2010.1.519.35.

    I have a parent page using a RadWindowManager which has an onbeforeunload handler to help prevent users from closing windows while there is unsaved data. The parent page dynamically opens any number of pages in a RadWindow. When I minimize then restore the RadWindow, the onbeforeunload handler on the parent is called. Subsequent minimize/restore/maximize also trigger the handler. Note, this only seems to happen in Internet Explorer (I tested in IE 8).

    Here's the parent:

    <telerik:RadWindowManager ID="WindowManager" runat="server">
            <a href="#" class="test-dynamic">Test Dynamic</a>
            <script type="text/javascript">
                window.onbeforeunload = function() { return 'Test'; }
                $('a.test-dynamic').click(function(e) {
                    var mgr = GetRadWindowManager();
                    var win =, null);
                    win.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize +  Telerik.Web.UI.WindowBehaviors.Maximize +  Telerik.Web.UI.WindowBehaviors.Minimize);
                    return false;

    The content of the window is irrelevant. In my test project, i just have a simple ASPX that just says "Window". You can create a new Telerik Web project and paste that into Default.aspx, then add a Window.aspx

    So, obviously I want to avoid the parent's onbeforeclose handler from being called. I can send a test project, if necessary.
  2. Georgi Tunev
    Georgi Tunev avatar
    7207 posts

    Posted 18 Oct 2010 Link to this post

    Hello Mike,

    To avoid the problem I would suggest using the following function (hooked to the OnClientShow property):
    function OnClientShow(wnd)
        var elem = wnd.get_popupElement();
        elem.onclick = function (e)
            return $telerik.cancelRawEvent(e);

    The reason for this behavior is that the buttons are actually <a> elements with href=javascript:void(0); which causes IE to fire the onbeforeunload event - this is a recognized problem, however there is still no fix for it from IE.
    To verify this you could try the following setup - as you can see there are no RadControls here, just pure HTML:

    <script language="javascript" type="text/javascript">
        var valueChanged = false;
        window.onbeforeunload = function()
            if (valueChanged)
                return "Unloading Page";
    <input type="text" id="inputText" onchange="valueChanged=true;" />
    <a href="javascript:void(0);">click after changing the value in the input</a>

    Best wishes,
    Georgi Tunev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Mike
    Mike avatar
    4 posts
    Member since:
    Oct 2007

    Posted 18 Oct 2010 Link to this post

    Ah, I see. Thanks!

    Your solution worked exactly in my test project, however it didn't seem to work in my application.

    In my application, I used this function to kill the href="javascript:void(0)" and it worked.

    function onWindowShow(wnd) {
        var elem = wnd.get_popupElement();
        jQuery('.rwControlButtons a', elem).removeAttr('href');

Back to Top