...

View Full Version : Closing search box when main page unloads



Remster
09-12-2011, 01:09 PM
Folks

I'm using the code below to create a pop-up search box that finds text strings on a contents page. The contents page contains a list of hyperlinks each of which opens a PDF document in the same window. The search box does exactly what it's intended to do, but the problem is this: if the user clicks on "Find next" or "Find previous" once the PDF document is open, an error occurs; the same error occurs if the user then navigates back to the contents page and clicks on "Find next" or "Find previous". I'm thinking the solution must be to get the search box to close as soon as the PDF document opens, but how do I achieve this?

Thanks

Remster


<html>

<head>
<title>Search this page</title>

<script language=JavaScript>

var rng = dialogArguments.document.body.createTextRange();
rng.collapse();

function findnext(){
if (document.all.strSearch.value.length < 1) {
alert("Please enter text to find.");
document.frmSearch.strSearch.focus();
}
else {
var searchval = document.all.strSearch.value;
rng.collapse(false);
if (rng.findText(searchval, 1000000000)) {
rng.select();
}
else {
alert("Finished searching page.");
rng.select(false);
document.frmSearch.strSearch.focus();
}
}
}

function findprevious(){
if (document.all.strSearch.value.length < 1) {
alert("Please enter text to find.");
document.frmSearch.strSearch.focus();
}
else {
var searchval = document.all.strSearch.value;
rng.collapse(true);
if (rng.findText(searchval, 1000000000, 1)) {
rng.select();
}
else {
alert("Finished searching page.");
rng.select(false);
document.frmSearch.strSearch.focus();
}
}
}

</script>

</head>

<body bgColor=buttonface>
<form name=frmSearch onsubmit="findnext();return false;" onsubmit="findprevious();return false;" action="" method=post>
<table cellSpacing=0 cellPadding=0 border=0>
<tr>
<td style="font-size: 12px; font-family: Arial" vAlign=top noWrap align=left>
<input id=strSearch style="margin-left: 15px; margin-top: 14px; width: 249;" name=strSearch><br>
<button style="margin-left: 15px; margin-top: 12px; width: 120px; height: 25px;" accessKey=f onclick=findnext(); name=btnFindNext>Find next</button>
<button style="margin-left: 9px; margin-top: 12px; width: 120px; height: 25px;" accessKey=f onclick=findprevious(); name=btnFindPrevious>Find previous</button></br>
</td>
</tr>
</table>
</form>
</body>

</html>

Remster
09-13-2011, 11:45 AM
Having done a bit more research, I've discovered that I need to place this in the body tag of the parent page:


onunload="parent.[name_of_pop-up].close()"

The problem is that my pop-up is a modeless dialog box, and there doesn't seem to be a way of giving it a name. So how to I refer to it?!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum