Close Window from RadMenu
1 Answer 11 Views
Carson
Top achievements
Rank 1
Carson asked on 14 Jul 2021, 03:03 PM

I have a RadMenu with a "Close Window" button. Each of the other buttons changes the visible RadPageView in a RadMultiPage. The close button works fine if it's the first button clicked. However, if any of the other buttons in the RadMenu are clicked first, clicking the Close Window button shows "Scripts may only close windows that were open by it" in the JavaScript console.

From what I understand, the problem is due to the RadMenu's postback (which is necessary in this case). Is there any way around this behavior to allow the "Close Window" button to keep working?

 

Ivan Danchev
Telerik team
commented on 19 Jul 2021, 01:49 PM

This appears to be a question about the RadMenu, a component in the UI for ASP.NET AJAX suite, rather than about the UI for ASP.NET MVC Menu. If that is the case, I'll transfer the thread to the ASP.NET AJAX forums.
Carson
Top achievements
Rank 1
commented on 19 Jul 2021, 06:06 PM

Oh, you are right. My mistake. Please make the transfer. Thank you.

1 Answer, 1 is accepted

Sort by
1
Accepted
Doncho
Telerik team
answered on 22 Jul 2021, 10:26 AM

Hi Carson,

I would assume that the page containing the RadMenu is opened from another page via some JavaScript or navigation URL. Such a scenario can be reproduced with native asp controls. For instance http://somup.com/cri360YTxc

InitialPage.aspx

<a href="TargetPage.aspx" target="_blank">Open Target Page</a>
TargetPage.aspx
<asp:Button Text="Postback" runat="server" />
<asp:Button Text="Close Window" OnClientClick="OnClientClicked(); return false;" UseSubmitBehavior="false" runat="server" />
<script>
    function OnClientClicked() {
        window.close();
        return false;
    }
</script>
If this is the case here I am afraid that closing a tab in the browser using the self.close() or window.close() is restricted due to security reasons. Here is a nice StackOverflow post on the matter that you may find useful to check out - https://stackoverflow.com/a/19768082

An alternative option could be if you load the external page in a RadWindow, that you can close afterward, see Overview.

If this is not the issue and my assumption is wrong, please share the markup declaration of the page containing the RadMenu along with the relevant code-behind and JavaScript logic so we can have a better overview and investigate further.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Menu
Asked by
Carson
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or