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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parent.frame.document problems 1

Status
Not open for further replies.

skills

Programmer
Jun 24, 2003
60
US
I have a problem with using parent.frame.document in my code.

I have multiple instances of parent.frame.document to change a frame url being performed in a row. The frame that is being changed is hidden. My problem is that only the last parent.frame.document of a selected group will actually work.

Any suggestions on possible solutions would be greatly appreciated.

Thanks,

Jonathan Hubacher
 
if you mean you're changing the location several times in a row immediately, like so

parent.frameName.location = "onething";
parent.frameName.location = "something";
parent.frameName.location = "anotherthing";

they're all executing, but your browser can't react that quickly so only the last completes. if you must have these execute in order, you need to come up with a method of determining when the last call finishes before calling the next.

an easy way would be to put script in onload in "onething" that changes self.location to "something", then have an onload script in "something" change self.location to "anotherthing"



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
My code looks like this, this will help explain what I mean.

<code>
if (cs2 == true)
{
index_page = &quot;cs2.htm&quot;;
search(index_page,input)
}
if (cssc == true)
{
index_page = &quot;cssc.htm&quot;;
search(index_page,input)
}
if (eso == true)
{
index_page = &quot;eso.htm&quot;;
search(index_page,input)
}

-----------------------------------------------

function search(first,find)
{
i = 0;
alert(&quot;the link is &quot; + first);
alert(&quot;the parent.location is &quot; + parent.filetree1.location.href);
parent.filetree1.location.href = first;
alert(&quot;the new one is &quot; + parent.filetree1.location.href);
while (i < parent.filetree1.document.links.length)
{
alert(&quot;I made it here&quot;);
parent.filetree2.location.href = parent.filetree1.document.links;
j = 0;
while (j < parent.filetree2.document.links.length)
{
var pdf_link = &quot;&quot;;
pdf_link = parent.filetree2.document.links[j];
var pdf_link_text = &quot;&quot;;
pdf_link_text = parent.filetree2.document.links[j].innerHTML;
alert(&quot;I made it here too&quot;);
compare(pdf_link,pdf_link_text,find);
j++;
}
i++;
}
}

This search function worked when I had it opening and closing windows, so I know the function works.

The thing is, only the last if statement in any selected set that is true, from above, works.

What I am doing here is making an internal search engine. If a subject, example cssc is selected from my form, then the cssc.htm file is to load into a hidden frame, and run through the search. then if the next one, eso is true as well, it does the same for eso.htm

I hope this maks sense.

Jonathan Hubacher
 
is this what you mean:

if cs2, cssc and eso are true, you want search() to be called 3 times. with the alert()s it works fine, but without the alert()s only the last call happens?



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Don't mind the alerts, they are strictly debugging tools.

I will back up a little further, this should help out a whole lot.

Look at this:

<FORM name = &quot;drawing_finder&quot; onSubmit=&quot;submitparams(window.document.drawing_finder.subject.value, window.document.drawing_finder.ESO.checked, window.document.drawing_finder.CS2.checked, window.document.drawing_finder.CSSC.checked, window.document.drawing_finder.GWC.checked, window.document.drawing_finder.HF.checked, window.document.drawing_finder.MICC.checked, window.document.drawing_finder.NWT.checked, window.document.drawing_finder.OIS.checked, window.document.drawing_finder.PCS.checked, window.document.drawing_finder.PIC.checked, window.document.drawing_finder.PRS.checked, window.document.drawing_finder.SCS.checked, window.document.drawing_finder.ALL.checked)&quot;;>
<B>SUBJECT: </B> <INPUT TYPE = &quot;text&quot; NAME = &quot;subject&quot; SIZE = &quot;40&quot;> <INPUT TYPE = &quot;submit&quot; value = &quot;Search&quot;>
<BR><BR>

<TABLE>
<TR>
<TD>
<B>SEARCH ONLY:</B>
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;CS2&quot; onClick=&quot;turnallboxoff();&quot;> CS2
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;CSSC&quot; onClick=&quot;turnallboxoff();&quot;> CSSC
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;ESO&quot; onClick=&quot;turnallboxoff();&quot;> ESO
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;GWC&quot; onClick=&quot;turnallboxoff();&quot;> GWC
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;HF&quot; onClick=&quot;turnallboxoff();&quot;> HF
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;MICC&quot; onClick=&quot;turnallboxoff();&quot;> MICC
</TD>
</TR>
<TR>
<TD></TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;ALL&quot; onClick=&quot;checkall();&quot;> ALL
</TD>
</TR>
...
</TABLE>
</FORM>

This is my form. When a box(s) are selected, then the program runs searches through the different .htm pages. Each page is a different section. Look at this code:

function submitparams(input,eso,cs2,cssc,gwc,hf,micc,nwt,ois,pcs,pic,prs,scs,all)
{
if (cs2 == true)
{
index_page = &quot;cs2.htm&quot;;
search(index_page,input)
}
if (cssc == true)
{
index_page = &quot;cssc.htm&quot;;
search(index_page,input)
}
...
This will run through search with each desired page. Search was shown in the last reply. Here is the frameset to show you that that is right.

<FRAMESET rows=&quot;62%, 38%,0%,0%,0%&quot;>
<frame src=&quot;search.htm&quot; name=&quot;search&quot; scrolling=&quot;no&quot; noresize>
<frame src=&quot;results.htm&quot; name=&quot;results&quot; scrolling=&quot;auto&quot;>
<frame src=&quot;hiddenpage.htm&quot; name=&quot;scroller&quot;>
<frame src=&quot;blank.htm&quot; name=&quot;filetree1&quot;>
<frame src=&quot;blank.htm&quot; name=&quot;filetree2&quot;>
</FRAMESET>

Now, what happens is that the only time filetree1 or filetree2 has a URL switched is when it is the last switch in a set. For example, let's say that we have 10 different

if (example == true)
{
index_page = &quot;example.htm&quot;;
search(index_page,input)
}

in a row, only the last one that is true will actually switch the URL of Filetree1. Let's say that we have cs2, cssc, and eso true. ESO is the only URL that will be shown in filetree1. Now, if you were to have 10 different ones, and the last one was xxxx, then xxxx would be the only one that would be placed in filetree1.

I hope this makes sense.

Jonathan Hubacher
 
this is because in essence, you are executing:

location.href = &quot;file1&quot;
location.href = &quot;file2&quot;
location.href = &quot;file3&quot;

these statements execute within milliseconds of each other, basically overwriting each other and you're left with the last one.



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
This is not the case, because if you throw an alert in in the middle of the
if (cs2 == true)
{
index_page = &quot;cs2.htm&quot;;
search(index_page,input)
}
if (cssc == true)
{
index_page = &quot;cssc.htm&quot;;
search(index_page,input)
}
...
set, the page is still not loaded. If it were actually loading each page, then the last one before the alert would be loaded in the frame, and that is not the case. Secondly, keep in mind that I had this script running perfectly fine by opening the windows and reading them, and then closing them. I switched to frames so that it would be cleaner.

Jonathan Hubacher
 
actually, i believe that since your calls to search() are inside the function submitparams(), either control is not returned to the browser until submitparams() returns, or they pile up so quickly that the last write wins.

here is my test page:

<html>
<head>
<title>test</title>
<script type=&quot;text/javascript&quot;>
function foo() {
document.getElementById(&quot;i1&quot;).src = &quot;f1.html&quot;;
alert(&quot;f1&quot;)
document.getElementById(&quot;i1&quot;).src = &quot;f2.html&quot;;
alert(&quot;f2&quot;)
document.getElementById(&quot;i1&quot;).src = &quot;f3.html&quot;;
}

</script>
</head>

<body>
<form>
<input type=&quot;button&quot; value=&quot;foo&quot; onclick=&quot;foo();&quot; />
<p/><iframe id=&quot;i1&quot;></iframe>
</form>
</body>
</html>

and the frames f1.html, f2.html, and f3.html contain nothing but the text &quot;f1&quot;, &quot;f2&quot; and &quot;f3&quot; respectively. you will see that the iframe does not load until the function foo() returns.




=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
That does not make sense. If I had to be out of submitparams for it to load, then why does it load the last one asked for inside of submitparams. Also, I don't think it would be the last one wins because when I throw an alert in the middle, it doesn't take a breath and show the loaded frame.

 
&quot;then why does it load the last one asked for inside of submitparams.&quot;
because that's when control leaves the function and returns to the browser, so the browser can process loading the document.


&quot;...when I throw an alert in the middle, it doesn't take a breath and show the loaded frame.&quot;
right, because control hasn't returned to the browser yet for it to load the document.



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Would it work if I had the frame reload after giving the parent.frame.document = ... command? If so, then how do I reload or refresh the frame.

Jonathan
 
Here is the layout of the program:

Upon Submit from form to submitparams,

submitparams is called:

this is the function that is used to decide which sections, cs2, cssc, eso, etc. are searched and not searched.

If a if statement is true:

index_page becomes the corresponding webpage
search is run, with indexpage and the input as params

Search takes the webpage parameter and makes it the new url in filetree1, which is hidden. The link list is then checked, and the first link inside the webpage param is loaded into filetree2. Then the description of the link is extracted and declared as pdf_link_text. The address and pdf_link_text are sent to compare, along with the input string.

Compare checks to see if the input string is found in the description. If so, the description is added to he description array, and the address is added to the address array.

Compare then closes and goes back to search. Search implements j by one, and the second link in filetree2 is sent to compare. This is done until there are no more links to send to compare.

Then i is incremented by one and the next link in filetree1 is loaded into filetree2, and the cycle continues until all the links in filetree1 are checked.

Search then returns to submitparams, and if the same procedure is done for all the valid if statements. After the last if statement, display results is called.

Display results displays the results in the results window.

That is how the program goes. It worked for me when I did it with windows

-Jonathan

 
you need some way of queueing the calls to search() so the next doesn't get called until the previous finishes.

one way would be to make submitparams() recursive. try this - notice i've given your checkboxes a value representing the filename, and i'm passing all checkbox values as one array. make sure your search() function returns true so submitparams() will wait for it:

function submitparams(input, arParams) {
if (!arParams || !arParams.length || arParams.length == 0) return true;
else {
if (arParams[0].length == 0) {
arParams = arParams.shift();
submitparams(input, arParams);
}
else if (search(arParams[0] + &quot;.htm&quot;, input)) {
arParams = arParams.shift();
submitparams(input, arParams);
}
}
}


<FORM name = &quot;drawing_finder&quot;
onSubmit=&quot;submitparams(this.subject.value,
[this.ESO.value,
this.CS2.value,
this.CSSC.value,
this.GWC.value,
this.HF.value,
this.MICC.value,
this.NWT.value,
this.OIS.value,
this.PCS.value,
this.PIC.value,
this.PRS.value,
this.SCS.value,
this.ALL.value])&quot;;>
<B>SUBJECT: </B> <INPUT TYPE = &quot;text&quot; NAME = &quot;subject&quot; SIZE = &quot;40&quot;> <INPUT TYPE = &quot;submit&quot; value = &quot;Search&quot;>
<BR><BR>

<TABLE>
<TR>
<TD>
<B>SEARCH ONLY:</B>
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;CS2&quot; value=&quot;cs2&quot; onClick=&quot;turnallboxoff();&quot;> CS2
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;CSSC&quot; value=&quot;cssc&quot; onClick=&quot;turnallboxoff();&quot;> CSSC
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;ESO&quot; value=&quot;eso&quot; onClick=&quot;turnallboxoff();&quot;> ESO
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;GWC&quot; value=&quot;gwc&quot; onClick=&quot;turnallboxoff();&quot;> GWC
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;HF&quot; value=&quot;hf&quot; onClick=&quot;turnallboxoff();&quot;> HF
</TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;MICC&quot; value=&quot;micc&quot; onClick=&quot;turnallboxoff();&quot;> MICC
</TD>
</TR>
<TR>
<TD></TD>
<TD>
<INPUT TYPE = &quot;checkbox&quot; NAME = &quot;ALL&quot; value=&quot;all&quot; onClick=&quot;checkall();&quot;> ALL
</TD>
</TR>
...
</TABLE>
</FORM>




=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
That may work, but I have no clue what it is doing. Could you explain it to me.

Thanks,

Jonathan
 
sure:

function submitparams(input, arParams) {
// only continue if arParams contains something
if (!arParams || !arParams.length || arParams.length == 0) return true;
else {
// if the current (first) element is empty, remove it and try again
if (arParams[0].length == 0) {
arParams = arParams.shift();
submitparams(input, arParams);
}
// else call search()
else if (search(arParams[0] + &quot;.htm&quot;, input)) {
// after search() is done, remove first element and try again
arParams = arParams.shift();
submitparams(input, arParams);
}
}
}




=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
This still does not work. I get the first link to be called on.htm, where that came from I don't know. Secondly, it still will not load the second page because it is in the submitparams still.

Take a look at &quot;How do I refresh a page in another frame&quot;, posted on 6/25 and seeif that may work for me as well.

Jonathan
 
Actually, &quot;Refresh a Page&quot; is the one I meant to have you look at.

Jonathan
 
i don't think that's going to work for you: &quot;refreshing&quot; is merely reloading the same document. your problem is that the document won't load in the first place until control returns from the function that changed the location.

what you need to do is devise a method of issuing ONE change to location.href, waiting for it to complete, then continuing with any other changes to location.href.

sketch it out on paper.

[tt]
stack of requests
|
|--> send next to search() --
|
^ |
| |
| |
| |
Y <-- any more? <---|
|
|
V

N
|
|
V

end
[/tt]

=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top