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

I was hoping to open the document in a menu control using a site map. I am using the following code in a sitemap but I get an error. I would like to be able to click on a menu item whether it opens a sample document in a new window, but not so that the original page moves to a new location (essentially nothing to do on the main page.)

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

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

+5
source share
6 answers

I ended up using the following:

<siteMapNode url="javascript:window.open('Sample.doc','SampleName'); void(0);" title="FAQs"  description="FAQs" />
+8
source

OnMenuItemDataBound ASP.NET, :

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;
    }
}
+3
javascript:widow.open

, window.open?
, script ;)

+1

, sitemap, , .

+1

target?

<siteMapNode url="Sample.doc" target="_blank" title="FAQs"  description="FAQs" />
0

target="_blank" , . :

private void Menu1_PreRender(object sender, EventArgs e)
{
    if (!IsPostBack) {
        MenuItem FAQsItem = new MenuItem("FAQs");
        FAQsItem.NavigateUrl = "~/Sample.doc"; //You'll need to figure out your correct URL
        FAQsItem.Target = "_blank";
        Menu1.Items.Add(FAQsItem);
    }
}

. PreRender, MenuItems, , target="_blank".

0

All Articles