View Full Version : How to target results in new tab or window

04-28-2017, 09:40 AM

Newbie here.

I was working with this script and would like the results to be targeted to a new window or tab and not quite sure how to go about it.

<form name="jksearch" action="http://www.google.com/search" method="get" onSubmit="jksitesearch(this)">

<p>Search JavaScript Kit:<br />
<input id="hiddenquery" type="hidden" name="q" />
<input name="qfront" type="text" style="width: 200px" value="navigator object" /> <input type="submit" value="Search" /><br />
<div style="font: bold 11px Verdana;">Google:<input name="se" type="radio" checked> Yahoo:<input name="se" type="radio"> MSN:<input name="se" type="radio">

<script type="text/javascript">

// All-in-one Internal Site Search script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit - http://www.javascriptkit.com/
// This notice must stay intact for use

//Enter domain of site to search.
var domainroot="www.javascriptkit.com"

var searchaction=[ //form action for the 3 search engines

var queryfieldname=["q","p","q"] //name of hidden query form for the 3 search engines

function switchaction(cur, index){

function jksitesearch(curobj){
for (i=0; i< document.jksearch.se.length; i++){ //loop through radio to see which is checked
if (document.jksearch.se[i].checked==true)
switchaction(document.jksearch.se[i], i)
document.getElementById("hiddenquery").value="site:"+domainroot+" "+curobj.qfront.value




<p style="font: normal 11px Arial">This free script provided by<br />
<a href="http://www.javascriptkit.com">JavaScript Kit</a></p>



04-29-2017, 03:23 AM
Add the highlighted:

<form name="jksearch" action="http://www.google.com/search" method="get" onSubmit="jksitesearch(this)" target="_blank">

That will require a new window or (more likely, given today's browsers) tab, unless the user's browser has restrictions on pages opening new tabs (most do not). You can also use "_new" instead of "_blank", in which case the browser will reuse the existing new window (if any) from a previous search for subsequent searches (again, if any). However, if a previous window was opened by targeting "_new" for something else, it will be reused even for the initial search. Alternatively, you can try using an arbitrary and unique target value. As long as it's not in use by some other page in the user's browser and not reserved*, it will establish a tab for results that will be reused only for results.

Any questions, or problems, feel free to ask.

The browser cache may need to be cleared and/or the page refreshed to see changes.

NOTE: Though you didn't ask, it might be tempting try to target an iframe or frame. However, Google for sure (last I checked), and probably most other search engines as well, has or likely will have restrictions that prevent that.

*Some names are reserved and cannot be used for window/tab names.

05-02-2017, 05:45 AM
Hi John,

thanks for the help. Worked like a charm!