Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a document in a separate window from a site map

I was hoping to open a document in a menu control using a sitemap. I am using the following code in the sitemap but get an error. I would like to be able to click on the menu item, have it open the sample doc in a new window, but not to have the original page navigate to a new place (essentially to do nothing on the main page.)

<siteMapNode url="javascript:window.open('Sample.doc','SampleName'); return false" title="FAQs"  description="FAQs" />

Any idea? Is there some javascript I can use that does not require me to register a function on every page?

like image 668
Sean Avatar asked May 06 '10 18:05

Sean


3 Answers

I ended up using the following:

<siteMapNode url="javascript:window.open('Sample.doc','SampleName'); void(0);" title="FAQs"  description="FAQs" />
like image 109
Sean Avatar answered Nov 03 '22 00:11

Sean


If you handle the OnMenuItemDataBound event on the ASP.NET Menu control, you can set the target attribute on the item there:

MyMenu.MenuItemDataBound += OnMenuItemDataBound

private void OnMenuItemDataBound(object sender, MenuEventArgs e)
{
    // Sets all menu items to open in new windows
    e.Item.Target = "_blank";

    // Uses a 'target' attribute in the XML sitemap if set:
    string targetAttributeValue = ((SiteMapNode)e.Item.DataItem)["target"];
    if (targetAttributeValue != null) {
        e.Item.Target = targetAttributeValue;
    }
}
like image 26
Tevin Avatar answered Nov 03 '22 00:11

Tevin


javascript:widow.open

Are you sure you don't mean window.open?
I don't think your script is that much related to widows ;)

like image 42
Sune Rasmussen Avatar answered Nov 03 '22 01:11

Sune Rasmussen