PDA

View Full Version : New page in same window



Burgin
12-21-2008, 06:40 AM
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?


<!--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;
}
-->

jscheuer1
12-21-2008, 06:59 AM
Change:


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

to:


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

Burgin
12-21-2008, 07:38 AM
I've tried your suggestion but it doesn't work. here's the page...

Wiki Tool (http://www.traveladvisorsgroup.co.uk/misc/wiki_tool.htm)

jscheuer1
12-21-2008, 12:36 PM
That page is a mess, so is this one, but at least it does what I think you want:


<!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:


<!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:


<!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>