View Full Version : Can drop down menus open links in a new window?

02-21-2008, 06:25 PM
I like the drop down menus that are available from DHTML Drive but none of them seem to have the option of opening a link in a new window. Is there any code that could be added to fix that?

The Anylink drop down menu is the one that I would prefer to use, at:



02-21-2008, 06:45 PM
Sure, the links in the area from Step 1, here:

//Contents for menu 1
var menu1=new Array()
menu1[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a>'
menu1[1]='<a href="http://www.freewarejava.com">Freewarejava.com</a>'
menu1[2]='<a href="http://codingforums.com">Coding Forums</a>'
menu1[3]='<a href="http://www.cssdrive.com">CSS Drive</a>'

//Contents for menu 2, and so on
var menu2=new Array()
menu2[0]='<a href="http://cnn.com">CNN</a>'
menu2[1]='<a href="http://msnbc.com">MSNBC</a>'
menu2[2]='<a href="http://news.bbc.co.uk">BBC News</a>'

are just ordinary links, you can do:

menu1[0]='<a href="http://www.javascriptkit.com" target="_blank">JavaScript Kit</a>'

as well as insert more complex javascript via an onclick event:

menu1[0]='<a href="http://www.javascriptkit.com" onclick="window.open(this.href, \'_blank\', \'width=400, height=375\');return false;">JavaScript Kit</a>'

Or you could do nothing special there, just set the base target for the page to _blank (goes in the head of the page):

<base target="_blank">

Then all of the links on that page will open in a new window.

02-21-2008, 11:55 PM
Thanks for that, I made the changes. But in a couple of instances the drop down menu with target = "_blank" added seems to cause my IE to regard the websites as pop ups and block them. Both websites are actually blogs. Is there a way to fix that?

My drop down menu is at: www.proudoftwerton.com (http://www.proudoftwerton.com) and the drop down menu is called Community Links (click).

02-22-2008, 02:26 AM
Which sites? Perhaps those sites are trying to pop up something after they are navigated to. In any case, the designer (that's you), has no control over the user's browser as far as things like pop up blocking go. All modern browsers can be set to block all pop ups, most pop ups, or no pop ups. The default is most. This means that the user must actually initiate the pop up by clicking on a link that pops it up. This condition is satisfied by the target attribute, but if the page launched by such an action has a more aggressive pop up associated with it, this will trigger the blocker.

Again, which specific sites?

04-18-2008, 09:06 PM
Sorry for the long delay in getting back.

The problem appears to be that when you try to get the anylink drop down menu to take users to a blog, and to get that blog to open in a new window, Internet Explorer 7 treats the blog as a pop-up and blocks it if you have pop-ups disabled.

So for example, I visit the home page of my website at http://www.proudoftwerton.com/index.html.
I then click on the anylink drop down menu called "Community Links (click)" on that page. I click on the link "Paul Crossley: Southdown" which should take me to a blog called "Southdown Bath". But instead, the browser blocks that site because I have pop-ups disabled.

The blocked site is http://www.readmyday.co.uk/SouthdownBath

All of the other sites that are blocked are blogs as well. It seems to be the combination of using javascript and asking a blog to open in a new window that causes this response from the browser. You can code a link to those sites in HTML with target="blank" and they open fine.

Is there a way around the problem?


04-19-2008, 05:02 AM
If you have pop ups totally disabled yes, any browser will prevent this. However that (pop ups totally disabled) is not the default setting for any major browser. There was no problem in IE 7 just now when I tried this. My setting for pop ups in IE 7 is:

Filter level:
Medium: Block most automatic pop-ups

Which is also the default for IE 7 - what it it ships with at least via automatic update for Win XP.

If you are truly concerned that some users will be blocked from experiencing your intended navigational pathways due to having tighter than usual pop up blocking settings, you must forgo using anything that will open a new window. Even target=_blank on a normal link will be blocked by some browsers with pop up blocking set to its highest setting.

As a side note on this issue, when I design a site, I often open things in new windows, as seems appropriate, both on and off site. However, the essential content of the site is all within normal link pathways. The way I figure is, most folks with pop ups totally disabled are used to missing out on certain things unless they make the case by case exceptions for them. But I design the site so that even they can view the essential content.

Now, like you, I don't want my users going off site to a link from my site (or the site I am designing) and losing the primary site. This is where I use pop ups. But I am fully aware that some will not be able to navigate that way if their settings are too restrictive.

04-20-2008, 03:49 PM
Thanks mate. I'll leave it as it is then. One less thing to do.