WordPress.org

Ready to get started?Download WordPress

Forums

Dropdown & _blank (6 posts)

  1. marcok
    Member
    Posted 6 years ago #

    Hello,

    I'm trying to figure out how to open sites from a dropdown menu in a new browser window ("_blank").

    Here's my code:

    <select name="some-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> <option value="">Topic</option>
    
    <option value="http://www.someurl.com"> Someurl.com </option>

    This code opens the someurl.com address in the same window. But how to open it in a new window?

    Any idea?

    Thanks a lot!

  2. TrishaM
    Member
    Posted 6 years ago #

    somewhere inside of the opening <a href="....."> tag you need to add "target="_blank" so it would look something like this;

    <a href="http://www.whateverdomain.com/" target="_blank">Anchor Text</a>

  3. marcok
    Member
    Posted 6 years ago #

    Thank you Trisha -

    but now the most important question... where is this tag in my code? lol

  4. TrishaM
    Member
    Posted 6 years ago #

    dumb question so forgive me,.......but where did you get the dropdown code you show above?

    Where does it appear in your site? (Post a link so we can look at it and your source code).

    Also, is this dropdown box created by a function? If so, post the function as well - if it's created by a function (maybe in your theme's functions.php file) then that might be where you'll find the <a href= tag....

  5. marcok
    Member
    Posted 6 years ago #

    Trisha, thank you again for your reply. Well, this code is the standard code of WP 2.5 (probably earlier versions as well?!).

    You can see the original code when you put your archives as a drop down menu on the sidebar...

  6. TrishaM
    Member
    Posted 6 years ago #

    Aha.......you are using a Widget.

    Okay this should work BUT back up your widgets.php file FIRST just in case :D

    Navigate to your /wp-includes/widget.php file

    At around line 882 you'll see this code:

    <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>

    Change it to add

    target="_blank"

    Exactly where I show it here:

    <li><a href="<?php the_permalink() ?>" target="_blank"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>

Topic Closed

This topic has been closed to new replies.

About this Topic