Welcome to WebmasterWorld Guest from 54.159.26.69

Forum Moderators: open

Message Too Old, No Replies

search form - open in new window

     

em007

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

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month