tags:

views:

57

answers:

4

I am working on a CMS site that uses dynamic navigation. There is one link on the site that I would like to be able to open in a new window. However, since this is a dynamic environment I can't add the standard, target="_blank" to the link. so how can i open the link in new window without using jquery ?

A: 

$("#linkid").attr("target", "_blank");

Or to target by a css style $(".linkclass")

Brian
That's how I would do it too, however he doesn't seem to want to use JQuery for some reason.
Pekka
I thought it said with; oops...
Brian
A: 

You can right click on the link and press "Open in new Window/Tab"

Seriously, you shouldn't overwrite the default behavior of the browser nor force the user to open a link in a new window. If the user want to open the link in a new window he already know how to do it (by selecting the entry in the popup menu, or even use a mouse gesture). But opening a link in the same window if the link is "forced" to open in a new window (with target="_blank") is much more difficult, specially if there is javascript involved (I really hate links like javascript:showDetails('12453563');)

Progman
A: 

For all links on the page without jQuery but with Javascript:

links=document.getElementsByTagName("a");
for(var i=0; i<links.length; i++) {
    links[i].target="_blank";
}

For just the link that you want, if it is giving a unique ID:

link=document.getElementByID("link_id");
link.target="_blank";

For the link you want with no ID provided, if you know the URL:

links=document.getElementsByTagName("a");
for(var i=0; i<links.length; i++) {
    if(links[i].href = "http://the/url/you/are/targeting") {
        links[i].target="_blank";
     }
}

For the link you want with no idea provided, if there's a given class associated with it:

links=document.getElementsByTagName("a");
for(var i=0; i<links.length; i++) {
    if(links[i].className = "blankLinkClass") {
        links[i].target="_blank";
     }
}
justkt
A: 

From your question it looks like that your using a CMS which generates the menu links dynamically and for you to add the _blank to the link, you need some help. Is this right? What CMS are you using?

Joey Ezekiel