Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I stop JS to open a new window??

Status
Not open for further replies.

kamedar

Programmer
Jan 3, 2002
2
CH
I have downloaded the following JavaScript. It´s a kind of search engine for my personal homepage. Now my problem is, that if i want to see the search results the javascript opens always a NEW window. But i would like that the results will be shown in the SAME window, so that the search mask will be overwritten.
Can anybody help me???

<html>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
var item = new Array();

/* Here is where all the magic happens.
Just enter as many additional pages that
that you want to search, then fill in the
additional listings for each page.

/
// &quot;Page Name&quot;,&quot;path&quot;,&quot;Page Title&quot;,&quot;Many,Key,Words&quot;,&quot;Descriptive Comments&quot;

c=0; item[c]=new Array(&quot;index.htm&quot;,&quot;&quot;,&quot;DemoSite&quot;,&quot;index,main,start,home,front&quot;,&quot;Demonstration search engine data about an imagined but probable internet site.&quot;);
c++; item[c]=new Array(&quot;content.htm&quot;,&quot;&quot;,&quot;Content&quot;,&quot;News&quot;,&quot;Contact details and general information about the creator of the site and what the site is about.&quot;);
c++; item[c]=new Array(&quot;agenda/agenda.htm&quot;,&quot;&quot;,&quot;Agenda&quot;,&quot;links,more,where,similar,friends&quot;,&quot;Links to my favourite sites which I find interesting. Other friends sites which have similar interests to my own.&quot;);

page=&quot;<html><head><title>Search Results</title></head><body bgcolor='white'><center><table border=0 cellspacing=10 width=80%>&quot;;

function search(frm) {
win = window.open(&quot;&quot;,&quot;&quot;,&quot;scrollbars&quot;);
win.document.write(page);
txt = frm.srchval.value.split(&quot; &quot;);
fnd = new Array(); total=0;
for (i = 0; i < item.length; i++) {
fnd = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != &quot;&quot;)
fnd += (j+1);
}
for (i = 0; i < fnd.length; i++) {
n = 0; w = -1;
for (j = 0;j < fnd.length; j++)
if (fnd[j] > n) { n = fnd[j]; w = j; };
if (w > -1) total += show(w, win, n);
fnd[w] = 0;
}
win.document.write(&quot;</table><br>Total found: &quot;+total+&quot;<br></body></html>&quot;);
win.document.close();
}
function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = &quot;<tr><td><a href='&quot;+link+&quot;'>&quot;+item[which][2]+&quot;</a> Score: &quot;+num+&quot;<br>&quot;;
line += item[which][4] + &quot;<br>&quot;+link+&quot;</td></tr>&quot;;
wind.document.write(line);
return 1;
}
// End -->
</script>
</HEAD>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<center>

<form method=get action=&quot;javascript:void(0)&quot; onsubmit=&quot;search(this); return false;&quot;>
<tr><td><input type=text name=srchval value=&quot;&quot;><input type=submit value=&quot;Search&quot;></td></tr>
</form>

</center>

</body>
</html>
 
try this one. it writes it in the same window.

<html>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
var item = new Array();

// &quot;Page Name&quot;,&quot;path&quot;,&quot;Page Title&quot;,&quot;Many,Key,Words&quot;,&quot;Descriptive Comments&quot;

c=0; item[c]=new Array(&quot;index.htm&quot;,&quot;&quot;,&quot;DemoSite&quot;,&quot;index,main,start,home,front&quot;,&quot;Demonstration search engine data about an imagined but probable internet site.&quot;);
c++; item[c]=new Array(&quot;content.htm&quot;,&quot;&quot;,&quot;Content&quot;,&quot;News&quot;,&quot;Contact details and general information about the creator of the site and what the site is about.&quot;);
c++; item[c]=new Array(&quot;agenda/agenda.htm&quot;,&quot;&quot;,&quot;Agenda&quot;,&quot;links,more,where,similar,friends&quot;,&quot;Links to my favourite sites which I find interesting. Other friends sites which have similar interests to my own.&quot;);

var page=&quot;<html><head><title>Search Results</title></head><body bgcolor='white'><center><table border=0 cellspacing=10 width=80%>&quot;;

function search(frm) {
win = window
txt = frm.srchval.value.split(&quot; &quot;);
fnd = new Array(); total=0;
for (i = 0; i < item.length; i++) {
fnd = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != &quot;&quot;)
fnd += (j+1);
}
for (i = 0; i < fnd.length; i++) {
n = 0; w = -1;
for (j = 0;j < fnd.length; j++)
if (fnd[j] > n) { n = fnd[j]; w = j; };
if (w > -1) total += show(w, win, n);
fnd[w] = 0;
}
page += &quot;</table><br>Total found: &quot;+total+&quot;<br></body></html>&quot;;
document.write(page)
}
function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = &quot;<tr><td><a href='&quot;+link+&quot;'>&quot;+item[which][2]+&quot;</a> Score: &quot;+num+&quot;<br>&quot;;
line += item[which][4] + &quot;<br>&quot;+link+&quot;</td></tr>&quot;;
page += line;
return 1;
}
// End -->
</script>
</HEAD>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<center>

<form method=get action=&quot;javascript:void(0)&quot; onsubmit=&quot;search(this); return false;&quot;>
<tr><td><input type=text name=srchval value=&quot;&quot;><input type=submit value=&quot;Search&quot;></td></tr>
</form>

</center>

</body>
</html>
 
if i understood it correctly, the same window is targeted by second parameter of open function:
window.open(&quot;&quot;,&quot;target_window&quot;,prefs)
& if you'd write to a window with the same name (target_window here) then you'd write to the same window (browser instance) Victor
 
thanks a lot for your support. sorry to bother you again, but unfortunatly both of your solutions didnt work properly. i have now a solution which only works in the internet explorer, but not in the netscape... can you maybe tell me why and where the problem is?

<!-- Begin
var item = new Array();

c=0; item[c]=new Array(&quot;index.htm&quot;,&quot;&quot;,&quot;DemoSite&quot;,&quot;index,main,start,home,front&quot;,&quot;Demonstration search engine data about an imagined but probable internet site.&quot;);
c++; item[c]=new Array(&quot;content.htm&quot;,&quot;&quot;,&quot;Content&quot;,&quot;News&quot;,&quot;Contact details and general information about the creator of the site and what the site is about.&quot;);

page=&quot;<html><head><title>Search Results</title></head><body bgcolor='#CCCCCC'><center><table border=0 cellspacing=10 width=80%>&quot;;

function search(frm) {
win = window
txt = frm.srchval.value.split(&quot; &quot;);
fnd = new Array(); total=0;
for (i = 0; i < item.length; i++) {
fnd = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != &quot;&quot;)
fnd += (j+1);
}
for (i = 0; i < fnd.length; i++) {
n = 0; w = -1;
for (j = 0;j < fnd.length; j++)
if (fnd[j] > n) { n = fnd[j]; w = j; };
if (w > -1) total += show(w, win, n);
fnd[w] = 0;
}
win.document.write(&quot;</table><br>Total found: &quot;+total+&quot;<br></body></html>&quot;);
win.document.close();
}
function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = &quot;<tr><td><a href='&quot;+link+&quot;'>&quot;+item[which][2]+&quot;</a> Score: &quot;+num+&quot;<br>&quot;;
line += item[which][4] + &quot;<br>&quot;+link+&quot;</td></tr>&quot;;
wind.document.write(page+line);
return 1;
}
// End -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top