Click to See Complete Forum and Search --> : JS search


djgaston
02-25-2003, 03:37 PM
This might be a little easier than my last post but I thought I would ask before I sit here and try to make this work. I just put in a JS search. I got all of the bugs worked out and the search works fine. What I do not like is when you type in the word, hit search, and the new window opens displaying the results... then you click on the page you want to go to and it opens that page inside the search results page. I would like to make it where it opens it in the previous window. If that is not possible, then I'll just set the search results page to be full size and leave it at that. I just thought maybe you all would have a suggestion as to how I can make the selected page display in the inactive browser window. Thanks ahead of time!

Charles
02-25-2003, 03:47 PM
<a href="http://www.w3.org/" onclick="if (top.opener) {top.opener.location.href = this.href; return false}">W3C</a>

djgaston
02-25-2003, 03:58 PM
Here's what I've got to work with:

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

Thanks
Danny

Jona
02-25-2003, 04:03 PM
Maybe...

function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"'>"+item[which][2]+"</a> Score: "+num+"<br>";
line += item[which][4] + "<br>"+link+"</td></tr>";
wind.document.write(line);
return 1;
}

Should be...

function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"' target='window.opener'>"+item[which][2]+"</a> Score: "+num+"<br>";
line += item[which][4] + "<br>"+link+"</td></tr>";
wind.document.write(line);
return 1;
}

Or...

function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='' onClick='window.opener.location="+link+"'>"+item[which][2]+"</a> Score: "+num+"<br>";
line += item[which][4] + "<br>"+link+"</td></tr>";
wind.document.write(line);
return 1;
}

Is that what you wanted?

djgaston
02-25-2003, 04:18 PM
Thanks. The first option works the best since it opens a completely new window.

You all obviously realize how dumb I am, so I won't hesitate to ask this... what can I put in to make that separate window open full screen?

I am amazed at how quickly everyone responds. This is a great forum. Thanks!

Jona
02-25-2003, 04:26 PM
Fullscreen would be...

function search(frm) {
win = window.open("","","scrollbars,fullscreen");
win.document.write(page);
//the rest of the code continues...

Of course, fullscreen only maximizes the window in Netscape, and it will really frustrate Internet Explorer users, because the only way to close a fullscreen window in IE (Internet Explorer) is to (1) have a closing link on the page, or (2) press ALT + CTRL + DEL and End Task of the page.

Instead, you may want to do this:

function search(frm){
width = screen.width;
height = screen.height;
win = window.open('','','scrollbars');
win.innerWidth = width;
win.innerHeight = height;
//the rest of the code...

I think that's right, but I may have it wrong...

djgaston
02-25-2003, 04:35 PM
Oops, that's what I meant... just maximized. Sorry for the confusion.

djgaston
02-25-2003, 04:39 PM
Okay, now I have:

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

With this, it opens the third window but it is still not maximized. Am I missing something? Thanks.

Jona
02-25-2003, 04:44 PM
Did you try it? If so, did it work? All except for the third window, you say? Let me see, I think this is it.

function show(which,wind,num) {
link = item[which][1] + item[which][0];
line = "<tr><td><a href='"+link+"' target='window.opener'>"+item[which][2]+"</a> Score: "+num+"<br>";
line += item[which][4] + "<br>"+link+"</td></tr>";
width = screen.width;
height = screen.height;
wind.innerWidth=width;
wind.innerHeight=height;
wind.document.write(line);
return 1;
}


..Hopefully that works for ya'.

djgaston
02-25-2003, 04:49 PM
I really appreciate your help.

It is still opening the third window fine but not maximized. Any other ideas?

Thanks.

Jona
02-25-2003, 07:17 PM
Try substituting "innerWidth" and "innerHeight" for "width" and "height" and if that doesn't work, try "Width" and "Height" because Javascript is case-sensitive.

djgaston
02-26-2003, 11:16 AM
Jona-

Still no luck. :-( Oh well, it's not the end of the world. At least the search works. All they have to do is click the maximize button themselves. No biggie.

Thanks for all of your help!!!!!!!!!!!

Jona
02-26-2003, 07:23 PM
You can try, wind.document.write('<scrip\t></scrip\t>') in it, and the script inside will be an auto-maximize script.

Teucca
02-27-2003, 06:25 AM
Hi!

I am using same original code for my search. Is it easy to edit that code so it won't open new window but replace that old one?

Jona
02-27-2003, 11:36 AM
Yep. Just use the same name for the second window as for the first. (Name both of them something like, "win")

Teucca
02-28-2003, 05:54 AM
I didn't understand your advice. I have a html-document index.html so how do I name that window so it won't open new window? I know, we newbies are annoying =D


<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var item = new Array();

c=0; item[c]=new Array("index.html","","DemoSite","index,main,start,home,front","Demonstration search engine data about an imagined but probable internet site.");
c++; item[c]=new Array("about.htm","","About Me","about,author,contact,email,who","Contact details and general information about the creator of the site and what the site is about.");
c++; item[c]=new Array("links.htm","","Links page","links,more,where,similar,friends","Links to my favourite sites which I find interesting. Other friends sites which have similar interests to my own.");
c++; item[c]=new Array("main.htm","main/","Main Page","content,main,focus","The main part of my site which contains what you have come to see. Lots of stuff like that and more great things. All in a sub directory.");
c++; item[c]=new Array("logo.jpg","main/images/","Link Logo","link,image,logo,graphic","The logo.jpg is just a small image which you can place on your site as a link to me. It's in a second level subdirectory.");

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


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

<BODY>

<center>

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

</center>
</BODY>
</HTML>