Html form to open search in new window only

Discussion in 'HTML & Website Design' started by bobocheez, Mar 27, 2009.

  1. #1
    Hi,
    I have a google search script written in html/javascript and I'm making a homepage for myself that runs from my computer. (the homepage is in one big html file)

    The search script works just fine, but opens the results in the same window. Is there a way to get a form to open only in a new window?

    Here's the basic stuff
    
    <form action="http://www.google.com/search" name="f">
     
    <input name="hl" type="hidden" value="en" />
    <input autocomplete="on" maxlength="2048" name="q" size="55" title="Google Search" value="" />
     
    <input name="btnG" type="submit" value="Google Search" />
     
    </form>
    
    HTML:

     
    bobocheez, Mar 27, 2009 IP
  2. woz2

    woz2 Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Does the target="_blank" trick work in forms?
     
    woz2, Mar 27, 2009 IP
  3. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #3
    That's only for anchor tags as far as I know.
     
    bobocheez, Mar 27, 2009 IP
  4. Oxi

    Oxi Peon

    Messages:
    78
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you gave me more information i might be able to help. I have used scripts for searching myself before and the target="_blank" used in the form tag worked for me. If its a more complex script your using where you are passing values i'd need to take a look at it..
     
    Oxi, Mar 27, 2009 IP
  5. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #5
    Here is the part that is in the html page.
    It would be easier if you copied it to a text editor for a better view though.

        <script type="text/javascript">
            window.google = { kEI: "Kb-4SbKrLcmMjAeFxIGkCA", kEXPI: "17259,17291,19942", kHL: "en" };
            var _gjwl = location;
            function _gjuc() {
                var a = _gjwl.hash.substring(1);
                if (/(^|&)q=/.test(a) && a.indexOf("#") == -1 && !/(^|&)cad=h($|&)/.test(a)) {
                    _gjwl.replace("search?" + a.replace(/(^|&)fp=[^&]*/g, "") + "&cad=h");
                    return 1
                }
                return 0
            };
            window._gjuc && location.hash && _gjuc();
    
            function addFave(UrL, TiTlE) {            
                if (window.sidebar) {
                    window.sidebar.addPanel(TiTlE, UrL, "");
                }
                else if (window.external) {
                if (navigator.appName != 'Netscape') {
                    window.external.AddFavorite(UrL, TiTlE);
                } else {
                alert('Not supported command. Please add manually to your favorite\'s.');    
                }
                } else {
                    alert('Not supported command. Please add manually to your favorite\'s.');                
                }
            };
    
            function setHome() {
                alert(navigator.appName);
                if (navigator.appName == 'Microsoft Internet Explorer') {
                    document.body.style.behavior = 'url(#default#homepage)';
                    document.body.setHomePage(window.location.href);
                }            
                else {
                    alert('Not supported command. Please set manually as your home page.');
                }
            }
        </script>
    
    
        <script type="text/javascript">
            google.y = {};
            google.x = function(e, g) {
                google.y[e.id] = [e, g];
                return false
            };
            window.clk = function(b, c, d, e, f, g, h) {
                if (document.images) {
                    var a = encodeURIComponent || escape;
                    (new Image).src = ["/url?sa=T", c ? "&oi=" + a(c) : "", d ? "&cad=" + a(d) : "", "&ct=", a(e), "&cd=", a(f), b ? "&url=" + a(b.replace(/#.*/, "")).replace(/\+/g, "%2B") : "", "&ei=Kb-4SbKrLcmMjAeFxIGkCA", g].join("")
                }
                return true
            };
            window.gbar = { qs: function() { }, tg: function(e) {
                var o = { id: 'gbar' };
                for (i in e) o[i] = e[i]; google.x(o, function() { gbar.tg(o) })
            }
            };
        </script>
    
    <!-- start page -->
    <center>
        <div id="gbar">
            <nobr><b class="gb1"><span id="Label_a0a">Web</span></b> 
            <a id="a1a" class="gb1" onclick="gbar.qs(this)" href="http://www.google.com/imghp?hl=en&amp;tab=wi" target="_blank"><font color="red">Images</font></a> 
            <a id="a2a" class="gb1" onclick="gbar.qs(this)" href="http://maps.google.com/maps?hl=en&amp;tab=wl" target="_blank"><font color="red">Maps</font></a> 
            <a id="a3a" class="gb1" onclick="gbar.qs(this)" href="http://news.google.com/nwshp?hl=en&amp;tab=wn" target="_blank"><font color="red">News</font></a> 
            <a id="a4a" class="gb1" onclick="gbar.qs(this)" href="http://video.google.com/?hl=en&amp;tab=wv" target="_blank"><font color="red">Video</font></a> 
            <a id="a5a" class="gb1" onclick="gbar.qs(this)" href="http://mail.google.com/mail/?hl=en&amp;tab=wm" target="_blank"><font color="red">Gmail</font></a> 
    </center>
    		</nobr>
        <center>
            <br clear="all" id="lgpd">
            <form action="http://www.google.com/search" name="f" method="_POST">
            <table cellpadding="0" cellspacing="0">
                <tr valign="top">
                    <td width="25%">
                        &nbsp;
                    </td>
                    <td align="center" nowrap>
                        <input name="hl" type="hidden" value="en" />
                        <input autocomplete="on" maxlength="2048" name="q" size="55" title="Google Search"
                            value="" />
                        <br>
                        <input name="btnG" type="submit" value="Google Search" onClick="window.open('','results')"  />
                        <input name="btnI" type="submit" value="I'm Feeling Lucky" />
                    </td>
                    <td nowrap width="25%" align="left">
                        <font size="-2">&nbsp;<a id="a7a" href="http://www.google.com/advanced_search?hl=en">Advanced Search</a><br>
                            &nbsp;<a id="a8a" href="http://www.google.com/preferences?hl=en">Preferences</a><br>
                            &nbsp;<a id="a9a" href="http://www.google.com/language_tools?hl=en">Language Tools</a></font>
                    </td>
                </tr>
                <!--
                <tr>
                    <td colspan="3" align="center">
                        <font size="-1">
                            <span id="LabelRadio"></span>
                            <input id="all" type="radio" name="meta" value="" checked />
                            <span id="LabelRadio1"></span>
                            <input id="lgr" type="radio" name="meta" value="lr=lang_en" />
                            <span id="LabelRadio2"></span>
                            <input id="cty" type="radio" name="meta" value="cr=countryEN" />
                            <span id="LabelRadio3"></span>
                        </font>
                    </td>
                </tr>
                -->
            </table>
            </form>
                
        </center>
        <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("UA-6684715-1");
    pageTracker._trackPageview();
    } catch(err) {}</script>
    HTML:
     
    bobocheez, Mar 27, 2009 IP
  6. woz2

    woz2 Peon

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I don't think so. This works for me:

    <form target="_blank" action="http://www.google.com/search" name="f">

    <input name="hl" type="hidden" value="en" />
    <input autocomplete="on" maxlength="2048" name="q" size="55" title="Google Search" value="" />

    <input name="btnG" type="submit" value="Google Search" />

    </form>
     
    woz2, Mar 27, 2009 IP
  7. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #7
    The thing with that is that I set my new windows to open as a tab and I'm getting 2 tabs when search is clicked.
    -the results and an about:blank page
     
    bobocheez, Mar 27, 2009 IP
  8. Oxi

    Oxi Peon

    Messages:
    78
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #8
    aye, just tested your script with the target="_blank" preference and all works fine. Just make sure you have it in your form element and didnt make any silly mistakes ;) hope all is well and good luck with the rest of your coding
     
    Oxi, Mar 27, 2009 IP
  9. bobocheez

    bobocheez Active Member

    Messages:
    403
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #9
    Yup its all good now, I had a javascript in there that opened the blank.

    Thanks for the support

    For anyone else viewing this make sure you take out the onClick out of the submit for the value Google Search
     
    bobocheez, Mar 27, 2009 IP