Results 1 to 4 of 4

Thread: New page in same window

  1. #1
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default New page in same window

    I've come across this script for searching Wikipedia but it opens the results page in a newWindow, what needs changing to open the results in the same window?

    Code:
    <!--begin
    var keyword;
    document.form.wsearch.value==keyword
    function fin_search_wiki()
    {
    if(document.form.wsearch.value=="")
    window.alert("Enter a keyword in the Search Box!");
    else{
    document.form.wsearch.value==keyword;
    if(document.form.engine_wiki.value=="wiki")
    window.open("http://en.wikipedia.org/wiki/Special:Search?search="+document.form.wsearch.value+"&fulltext=Search");
    else
    window.alert("Select Your Search Engine");
    }
    return;
    }
    -->

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Change:

    Code:
    window.open("http://en.wikipedia.org/wiki/Special:Search?search="+document.form.wsearch.value+"&fulltext=Search");
    to:

    Code:
    window.open("http://en.wikipedia.org/wiki/Special:Search?search="+document.form.wsearch.value+"&fulltext=Search", "_self");
    - John
    ________________________

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

  3. #3
    Join Date
    Jan 2006
    Location
    Derbyshire, UK
    Posts
    74
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default

    I've tried your suggestion but it doesn't work. here's the page...

    Wiki Tool

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That page is a mess, so is this one, but at least it does what I think you want:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <head>
    	<title>Wikipedia Tool</title>
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    	<meta http-equiv="imagetoolbar" content="no">
    
    
    </head>
    <body>
    
    
        <div id="body-right">
    	  <p>&nbsp;</p>
    	  <p>&nbsp;</p>
    	  <div id="wiki">
    	  <form action="#" id="searchform" name="form" onsubmit="fin_search_wiki();return false;">
    	  <input name="ysearch" id="ysearch" type="text" value="Search" onKeyPress="checkKey()" onFocus="if (this.value=='Search'){this.value='';};return false;" onBlur="if (this.value==''){this.value='Search';return false;}">
          <input name="submit" type="image" src="http://www.traveladvisorsgroup.co.uk/assets/images/logos/wiki_neg.gif" alt="Search for information from Wikipedia!" width="86" height="16" />
          <input name="hidden" type="hidden" id="engine_wiki" value="wiki">
    	  </form></div>
    	  <p>&nbsp;</p>
    	  <p>&nbsp;</p>
    	  <p>&nbsp;</p>
    	  <p>&nbsp;</p>
    	  <p>&nbsp;</p>
    	  <p>&nbsp;</p>
        </div>
    	<script type="text/javascript">
    	  <!-- begin
    var keyword;
    document.form.ysearch.value==keyword
    function fin_search_wiki()
    {
    if(document.form.ysearch.value=="")
    window.alert("Enter a keyword or a “news item” in the Search Box!");
    else{
    document.form.ysearch.value==keyword;
    if(document.form.engine_wiki.value=="wiki")
    window.open("http://en.wikipedia.org/wiki/Special:Search?search="+document.form.ysearch.value+"&fulltext=Search", "_self");
    else
    window.alert("Select Your UK Search Engine");
    }
    return;
    }
    // -->
        </script> 
    
    </body>
    </html>
    But you really need no javascript to accomplish the basic goal:

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <head>
    	<title>Wikipedia Tool</title>
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    
    
    	  <p>&nbsp;</p>
    	  <p>&nbsp;</p>
    	  <form action="http://en.wikipedia.org/wiki/Special:Search">
        <div>
    	  <input name="search" type="text" value="Search">
          <input type="image" src="http://www.traveladvisorsgroup.co.uk/assets/images/logos/wiki_neg.gif" alt="Search for information from Wikipedia!">
          <input name="fulltext" type="hidden" value="Search">
        </div>
    	  </form>
    </body>
    </html>
    Which then led me to this:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <head>
    <title>Wikipedia Tool</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    span { 
     font-variant: small-caps;
    }
    input {
     vertical-align: middle;
    }
    span input {
     width: 86px;
     height: 16px;
     vertical-align: bottom;
     padding-bottom: 0.375ex;
    }
    </style>
    
    <script type="text/javascript">
    
    (function(){
     var check = function(e){
      var t = e || window.event, v;
      t = t.target || t.srcElement;
      t = t.elements.search;
      t.blur();
      v = t.value;
      if (!v || v == 'Search'){
       alert('Please Enter a Keyword or a \u201cNews Item\u201d in the Search Box.');
       if (e.preventDefault)
        e.preventDefault();
       t.focus();
       return false;
      }
      return true;
     };
    
     var focusBlur = function(e){
      e = e || window.event;
      var i = e.target || e.srcElement, t = e.type, v = i.value;
      i.value = t == 'blur' && v == ''? 'Search' : t == 'focus' && v == 'Search'? '' : v;
     };
    
     var init = function(){
      var f = document.forms.wiki;
      if (f.addEventListener){
       f.addEventListener('submit', check, false);
       f = f.elements.search;
       f.addEventListener('focus', focusBlur, false);
       f.addEventListener('blur', focusBlur, false);
      }
      else if (f.attachEvent){
       f.attachEvent('onsubmit', check);
       f = f.elements.search;
       f.attachEvent('onfocus', focusBlur);
       f.attachEvent('onblur', focusBlur);
      }
     };
    
     if (window.addEventListener)
      window.addEventListener('load', init, false);
     else if (window.attachEvent)
      window.attachEvent('onload', init);
    })();
    
    </script>
    </head>
    <body>
     <p>&nbsp;</p>
     <p>&nbsp;</p>
     <form name="wiki" action="http://en.wikipedia.org/wiki/Special:Search">
      <div>
       <span>Search Term(s):</span> <input name="search" type="text" value="Search">
       <span><input type="image" 
        src="http://www.traveladvisorsgroup.co.uk/assets/images/logos/wiki_neg.gif" 
        alt="Search for information from Wikipedia!" 
        title="Search for information from Wikipedia!"></span>
       <input name="fulltext" type="hidden" value="Search">
      </div>
     </form>
    </body>
    </html>
    Last edited by jscheuer1; 12-21-2008 at 02:38 PM. Reason: add info
    - John
    ________________________

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

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
  •