homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Open extendSearch link in New Window

 12:52 am on Nov 13, 2008 (gmt 0)

How can I get the hyperlink below to open in a new window? Target="_blank" does not work.

<script type="text/javascript">
function extendSearch(addon) {
window.location.search += addon;
<a href="#" onclick="extendSearch('&page=2');return false">



 1:46 am on Nov 13, 2008 (gmt 0)


function extendSearch(addon) {
window.open(window.location.href + addon, '_blank' );


 4:25 pm on Nov 13, 2008 (gmt 0)

Thanks for your help. When I tried the suggestion, the new window opened to the following address:


How can I get the new window to open to the address below?


[edited by: Fotiman at 6:26 pm (utc) on Nov. 13, 2008]
[edit reason] Examplified the URLs [/edit]


 6:33 pm on Nov 13, 2008 (gmt 0)

You'd want to first check to see if there is a ? in the current location URL. If not, then append one on, if so, then append '&' instead.

function extendSearch(addon) {
if (window.location.href.indexof('?') == -1) {
// Append ?
addon = '?' + addon;
else {
// Append &amp;
addon = '&amp;' + addon;
window.open(window.location.href + addon, '_blank');

Or the more condensed form:

function extendSearch(addon) {
window.open(window.location.href + (window.location.href.indexOf('?') == -1 ? '?' : '&amp;') + addon, '_blank');

And make sure your links don't include the &.

[edited by: Fotiman at 6:37 pm (utc) on Nov. 13, 2008]


 6:38 pm on Nov 13, 2008 (gmt 0)

<a href="#" onclick="extendSearch('page=2');return false">

(Though it's important to note that this link will not work for any visitor, including search engines, that have JavaScript disabled)


 9:42 pm on Nov 14, 2008 (gmt 0)

Thank you, Fotiman! The "condensed" version of your Javascript code worked for me!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved