Results 1 to 3 of 3

Thread: How to target results in new tab or window

  1. #1
    Join Date
    Apr 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool How to target results in new tab or window

    Hi,

    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.

    Code:
    <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">
    </div>
    
    <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
    "http://www.google.com/search",
    "http://search.yahoo.com/search",
    "http://search.msn.com/results.aspx"
    ]
    
    var queryfieldname=["q","p","q"] //name of hidden query form for the 3 search engines
    
    function switchaction(cur, index){
    cur.form.action=searchaction[index]
    document.getElementById("hiddenquery").name=queryfieldname[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
    }
    
    
    </script>
    
    </p>
    
    </form>
    
    <p style="font: normal 11px Arial">This free script provided by<br />
    <a href="http://www.javascriptkit.com">JavaScript Kit</a></p>
    Thanks.

    /Cynthia
    Last edited by jscheuer1; 04-29-2017 at 03:08 AM. Reason: format code

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,252
    Thanks
    75
    Thanked 3,395 Times in 3,356 Posts
    Blog Entries
    12

    Default

    Add the highlighted:

    Code:
    <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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2017
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi John,

    thanks for the help. Worked like a charm!

    /Cynthia

Similar Threads

  1. Target=“_blank” vs window.open
    By Rain Lover in forum HTML
    Replies: 3
    Last Post: 07-30-2014, 03:08 PM
  2. maximizing target window size
    By gib65 in forum HTML
    Replies: 1
    Last Post: 10-16-2009, 10:44 PM
  3. Target URL with window.print?
    By JBottero in forum JavaScript
    Replies: 0
    Last Post: 05-13-2009, 02:38 AM
  4. Carousel II (2) Open Target in SAME window
    By npimpfellow in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-01-2009, 03:36 AM
  5. Specify target window size without Javascript?
    By Eternal_Howl in forum HTML
    Replies: 4
    Last Post: 07-28-2007, 05:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •