Community & Support
Home / Community & Support / Knowledge Base / RadControls for ASP.NET and ASP.NET AJAX / Menu / Prevent opening a disabled menu item in new tab

Prevent opening a disabled menu item in new tab

Article Info

Rating: Not rated

Article information

Article relates to

 RadMenu for ASP.NET AJAX
 Telerik.Web.UI (v.2008.1.415)

RadMenu for ASP.NET v.4.4

Created by

 Veskoni, Telerik

Last modified by

 Veskoni, Telerik



PROBLEM
You can open a disabled menu item if you right click on it and select Open in new Tab.


SOLUTION


HTML:
<telerik:RadMenuItem runat="server"  
    Text="Disabled"  
    Enabled="false"  
    NavigateUrl="http://www.telerik.com"
</telerik:RadMenuItem> 

Javascript:

<script type="text/javascript"
 
var div2 = document.getElementById("RadMenu2"); 
 
if (div2.addEventListener) 
    //Firefox way 
    div2.addEventListener("contextmenu", onContextMenuAjax, false); 
else if (div2.attachEvent) 
    //IE way 
    div2.attachEvent("oncontextmenu", onContextMenuAjax); 
 
function onContextMenuAjax(e) 
    if ($telerik.isIE) 
    { 
        //IE way 
        if (Sys.UI.DomElement.containsCssClass(e.srcElement.parentElement, 'rmDisabled')) 
        { 
           return false;     
        } 
        else 
        { 
            return true
        } 
    } 
    else 
    { 
        //Firefox way 
        if (Sys.UI.DomElement.containsCssClass(e.target.parentNode, 'rmDisabled')) 
        { 
           e.stopPropagation();         
        }    
    } 
</script> 





HTML:
<rad:RadMenuItem runat="server"  
    Text="Disabled"  
    Enabled="false"  
    NavigateUrl="http://www.telerik.com"
</rad:RadMenuItem> 

Javascript:
<script type="text/javascript"
var div1 = document.getElementById("RadMenu1"); 
 
if (div1.addEventListener) 
    //Firefox way 
    div1.addEventListener("contextmenu", onContextMenu, false); 
else if (div1.attachEvent) 
    //IE way 
    div1.attachEvent("oncontextmenu", onContextMenu); 
 
function onContextMenu(e) 
    if (e.srcElement) 
    { 
        //IE way 
        if (e.srcElement.isDisabled) 
        { 
            return false
        } 
        else 
        { 
            return true
        } 
    } 
    else if (e.target) 
    { 
        //Firefox way 
        if (e.target.parentNode.disabled == "disabled"
        { 
            e.stopPropagation(); 
        } 
    }     
</script> 

Note:
The problem is fixed since 2009.3.1103.

Comments

There are no comments yet.
If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.