DotNetNuke Skins and Resources by ThinkofDesign

Forums

How to open menu item in new window

I'm using the Beyond CSS free skin, and I think it's a great skin, thank you. 

I have some links as tabs on the vertical menu, which open an external URL, and I would like to have them open in a new window if possible.  The "open in new window" option isn't available, and I would like to keep them in the main menu, rather in the Links module.

Any help is greatl appreciated, thanks!

Unfortunately there is no such functionality out of the box so the only possible solution I can think is using JavaScript.

Put a Text/Html module in your home page and go to this module's settings. Open the Advanced Settings and check the 'Display Module On All Pages?' option. Then below that option in the Header textarea put one of the following scripts.

If you want all items that link to external URLs to open in a new window use the script below:

<script type="text/javascript">
<!--
var menuLinks = document.getElementById('smenu').getElementsByTagName('a');
for(j=0;j<menuLinks.length;j++){
    if(menuLinks[j].href.indexOf('test.thinkofdesign.com') == -1){
        menuLinks[j].target = '_blank';
    }
}
-->
</script> 

Of course you have to replace 'test.thinkofdesign.com' with your URL so the script can identify which items link to internal pages on your site.

If you want to be even more flexible so only specific items to open in a new window, then use the script below:

<script type="text/javascript"> </script>

In the above you have to replace 'Item Title 1', 'Item Title 2' etc. with the titles of the menu items that you want to open in a new window. This is case sensitive. You can add more items by adding another if statement.

And if you don't plan to use this module to put also visible text for your guests, go to the Basic Settings and Uncheck the 'Display Container?' check box so the module will be invisible.

Hope that helps.

Cheers

Hmm... The forums keep striping my code in the scripts. I'll try to fix this but till then you can find the scripts in the attached txt.

Sorry about that!


Attachment: How to open menu item in new window.txt

OK, scripts look OK also in my first post now!

Yes!!!  Thank you so much!




ActiveForums 3.7