This is a migrated thread and some comments may be shown as answers.

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

2 Answers 112 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 13 Oct 2010, 09:01 PM
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">
    </telerik:RadWindowManager>
    <div>
        <a href="#" class="test-dynamic">Test Dynamic</a>
    </div>
        <script type="text/javascript">
            window.onbeforeunload = function() { return 'Test'; }
            $('a.test-dynamic').click(function(e) {
                var mgr = GetRadWindowManager();
                var win = mgr.open(null, null);
                win.setSize(700,700);
                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);
                win.setUrl('Window.aspx');
                win.setActive(true);
                return false;
            });
             
        </script>

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 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 18 Oct 2010, 01:42 PM
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";
    }
</script>
 
<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
0
Mike
Top achievements
Rank 1
answered on 18 Oct 2010, 09:48 PM
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');
}

Tags
Window
Asked by
Mike
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Mike
Top achievements
Rank 1
Share this question
or