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?
I ended up using the following:
<siteMapNode url="javascript:window.open('Sample.doc','SampleName'); void(0);" title="FAQs" description="FAQs" />
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;
}
}
javascript:widow.open
Are you sure you don't mean window.open
?
I don't think your script is that much related to widows ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With