homepage Welcome to WebmasterWorld Guest from 54.196.24.103
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
search form - open in new window
em007




msg:4426070
 3:47 pm on Mar 7, 2012 (gmt 0)

Hi, I found this script on the net. I would like it to open in a new tab/window.

How can this be achieved?


<script type="text/javascript">
function dosearch() {
var sf=document.searchform;
for (i=sf.sengines.length-1; i > -1; i--) {
if (sf.sengines[i].checked) {
var submitto = sf.sengines[i].value + escape(sf.searchterms.value);
}
}
window.location.href = submitto;
return false;
}
</script>



<form name="searchform" onSubmit="return dosearch();">
Search:<br />
<input name="sengines" type="radio" value="http://www.google.com/search?q="> Google<br />
<input name="sengines" type="radio" value="http://www.altavista.com/web/results?q="> Alta Vista<br />
<input name="sengines" type="radio" value="http://www.dogpile.com/info.dogpl/search/web/"> Dogpile<br />
<input name="sengines" type="radio" value="http://search.yahoo.com/search?p="> Yahoo!<br />
For:
<input type="text" name="searchterms">
<input type="submit" name="SearchSubmit" value="Search">
</form>

 

rocknbil




msg:4426106
 5:04 pm on Mar 7, 2012 (gmt 0)

Welcome aboard em007, target the URL to a new window:

var url = sf.sengines[j].value + escape(sf.searchterms.value);
var day = new Date();
var id = day.getTime();
var params = 'width=700,height=700,scrollbars,resizable';
var win = open(url,id,params);

em007




msg:4426112
 5:17 pm on Mar 7, 2012 (gmt 0)

Thank you.

Sorry, I'm not familiar with javascript. Where do I put that code to make it work? I tried to put it in the header but it still opens in the same window.

rocknbil




msg:4426567
 5:26 pm on Mar 8, 2012 (gmt 0)

Heh. We're here to help, teach, and in doing so learn, not do the work for you. :-) That code was typed on the fly and MAY contain errors (in fact, looking at it, has an error in logic.) Try just replacing this one line

window.location.href = submitto;

with this

var day = new Date();
var id = day.getTime();
var params = 'width=700,height=700,scrollbars,resizable';
var win = open(submitto,id,params);

em007




msg:4426649
 8:10 pm on Mar 8, 2012 (gmt 0)

I understand what you mean but I don't have the intention to learn javascript. I just wanted this thing too work and guessed it would be a peace of cake for someone skilled as you. Usually I search for the answer but couldn't find it in this case.

Anyway, your code works nicely. Thank you, I appreciate your help.

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved