[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

parent.frames[2].location=...

Posted on 1998-11-01
17
Medium Priority
?
755 Views
Last Modified: 2008-02-26
Hello All:

this should be a piece of cake, and in fact, my script works fine in NN4 and NN3.  But I am going crazy trying to figure out the solution in IE 4.0.

O.K.:

1.framed, chromeless (no toolbar) site -- 3 frames
2.frameA contains a textbox for typing in URL.
3.after some form validation, the Javascript loads said URL into another frame, frame B.
4. easy so far.

here's the code I use in frameA...


function gotoURL(URLFORM) {

var str = URLFORM.address.value;
// some form validation stuff follows
// finally...

parent.frames[2].location=str;
return false;
}

5. Here's the HTML from frameA...

<form name="URLFORM" onSubmit="return gotoURL(this)">
<input Type="text" value="http://" Name="address" size="30">
</form>

I know this can be done with a Submit button, but that dose not please the client, and it's more natural to type in the URL and press the ENRER key!

7. As I have it, it works fine in IE4.0 , but once a new page loads into frameB, it does not register in the browser's history. It is as if you redirect to a new page using location.replace() method! Even the browser's back button cannot take you to the previous page. Why?
works fine in NN3 and NN4.

Thanks in advance, and look forward to any suggestions.

Emad
0
Comment
Question by:emadgharavi
  • 9
  • 5
  • 2
  • +1
17 Comments
 
LVL 8

Expert Comment

by:jbirk
ID: 1273370
I'm not sure what the problem is, but there are a few things you might be able to try.

Try referring to the frame by name instead of by array index.
You have:
parent.frames[2].location=str;
change it to use the name, somthing like this:
parent.frame_name.location=str;

If that also doesn't work, try using location.href=str

Good luck, and I hope someone can come up with a solution if this doesn't work!
-Josh
0
 

Author Comment

by:emadgharavi
ID: 1273371
Josh:

hate to say it, but done all that and none of the following have worked thus far.

parent.frameA.location= str
parent.frameA.location.href=str
parent.frameA.assign(str)

Sorry
0
 

Author Comment

by:emadgharavi
ID: 1273372
Josh:

hate to say it, but done all that and none of the following have worked thus far.

parent.frameA.location= str
parent.frameA.location.href=str
parent.frameA.assign(str)

Sorry
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:jbirk
ID: 1273373
OK, maybe the problem comes in with the fact that this event is occuring onSubmit.
So somehow the IE engine gets confused with the form submission occuring at the same time.
If you used a button, you wouldn't have to have the submission, but you already said you didn't want that....

I'm not sure what can be done other than that.  Have you tried using an <input type="button" onClick="gotoURL(this)">?  I know it doesn't look great, but it may fix it.  You could also detect the browser, and put that in just for IE 4 users with a document.write if that does work.

-Josh
0
 
LVL 10

Expert Comment

by:kollegov
ID: 1273374
Well, I just tested script below it in MIE4 and NN4.04
and it works perfectly including normal history back/forward
operation.

Note that I used framest with 2 frames only, so I use frames[1]
(frames are indexed from 0 :)
Other minor change here:
   parent.frames[1].location=str+"";

This is a magic tip for MIE :)
Don't ask me what the difference but
parent.frames[1].location=URLFORM.address.value;
Sometimes don't work correctly, I noticed this problem earlier...

------frameset ----
<HTML>
<FRAMESET cols="50%,*">
 <FRAME NAME="left"  SRC="kaka.html" > 
 <FRAME NAME="right" src="frameright.html">  
</FRAMESET>
</HTML>

----- file kaka.html ---
<script>
function gotoURL(URLFORM)
{ var str = URLFORM.address.value;

   parent.frames[1].location=str+"";
   return false;
}
</script>
<form name="URLFORM" onSubmit="return gotoURL(this)">
<input Type="text" value="http://" Name="address" size="30">
</form>

---other frame don't matter---

Script tested with NN4.04, MIE4.01 Win95...
0
 

Author Comment

by:emadgharavi
ID: 1273375
Yepp:

Actually  the page is setup right now using document.write() with an image 'button' using the onClick handler for MSIE, but since this is an intranet site for a company of 500+ employees who just had to have Win '98 installed on their 200 MHz Dell PCs at the same time, and who just do not want to use Netscape, I'm 'up deep S*** creek with no paddle'!

The methods you suggested do work, but again, I just can't go that route.

Thanks anyway, and if no one else posts a working solution in a day or do, you got the points.
0
 

Author Comment

by:emadgharavi
ID: 1273376
To Kollegov:

Thanks for the tip. Time to fess up.  The page actually has five frames not two (or three as I indicated in my first posting) -- I just didn't want to confuse the issue by going into the frameset structure.  O.K. the form is in the first frame, frameA and the new page is to be loaded into the fifth frame, frameE.

The problem is not that..

parent.frames[4]location=str

.dose not work--it does.  But having loaded a new page the history Back action -- whether performed using the browser's own button or a parent.frames[4].history.back()-- does not load the previous page.  In other words with any URL submitted via the form, MSIE 4.0/4.01 behaves as if the new page was loaded with the location.replace() method, simply eliminating the previous page from history.

This is the problem.  I've had many headaches in the past dealing with javascript and multiple (>2) frames in IE and this one seems to be a real pain.  I tried your str + "" deal with no luck-- works with 2 frames, not with the 5 I'm dealing with.

I'm thinkin' it's a bug since NN3 and NN4 work just fine.
Do you have any ideas for multiple frames? Or is there a way to do this with VBScript?

Emad
0
 

Author Comment

by:emadgharavi
ID: 1273377
I think I should have posted the frameset structure after all, as there are nested frames involved here:

<FRAMESET rows="30,97,*">
  <FRAME NAME="FrameA"  SRC="page1.html" >   
  <FRAMESET cols="120,*,120">
    <FRAME NAME="FrameB"  SRC="page2.html" >   
    <FRAME NAME="FrameC"  SRC="page3.html" >   
    <FRAME NAME="FrameD"  SRC="page4.html" >   
  </FRAMESET>
  <FRAME NAME="FrameE"  SRC="page5.html" >   
</FRAMESET>


The form is in FrameA, the page to be loaded in FrameE.
Again the problem is new page loaded in FrameE removes page5.htm from history!

See my first posting for code used.
0
 
LVL 4

Expert Comment

by:rafistern
ID: 1273378
Try this:

<form name="URLFORM" action="javascript:gotoURL(this)">
<input Type="text" value="http://" Name="address" size="30">
</form>

0
 

Author Comment

by:emadgharavi
ID: 1273379
rafistern:



Thanks for the suggestion.  Tried it, but apparently can't process froms with action="javascript:...".  

0
 

Author Comment

by:emadgharavi
ID: 1273380
One final thought:

is it possible to use IE's event model to capture the keystrokes, and if ENTER is pressed to process the form?

I am just guessing that this may work.
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1273381
Yes you can do that.  It would look like this:
if (document.all) //IE4 only
 {document.onkeypress=handler;
 }
function handler()
{var i;
 i=window.event.keyCode;
 if (i==13) //if enter was pressed
  {parent.frames[whatever].location=processed str;
  }
}

There was some pseudo code in there but you know how to do that part.

Give this a try and see if it works for you!
Of course IE 3 won't do this... (have you tried it yet, dare I ask?)

Good luck!
-Josh
0
 

Author Comment

by:emadgharavi
ID: 1273382
Josh:

Thanks again. Already tried that, disn't work. Don't think you can deal with a form element's event handler that way. I know it's possible to use explicit event handler for buttons like...

<FORM>
<INPUT TYPE="button" NAME="myButton" VALUE="click here">
<SCRIPT LANGUAGE="JavaScript" EVENT="onclick" FOR="myButton">
<!--

alert("Thank you for clicking the button.");

// -->
</SCRIPT>
</FORM>

. but how can you use the onkeypress enevt in this way?

Any thoughts?
0
 
LVL 10

Accepted Solution

by:
kollegov earned 300 total points
ID: 1273383
<FRAMESET rows="30,97,*">
        <FRAME NAME="FrameA"  SRC="page1.html" >
        <FRAMESET cols="120,*,120">
          <FRAME NAME="FrameB"  SRC="page2.html" >   
          <FRAME NAME="FrameC"  SRC="page3.html" >   
          <FRAME NAME="FrameD"  SRC="page4.html" >   
        </FRAMESET>
        <FRAME NAME="FrameE"  SRC="page5.html" >   
</FRAMESET>

//----- page1.html ------
<script>
      function gotoURL(URLFORM)
      { var str = URLFORM.address.value;

         top.FrameE.open(str,"FrameE");
         return false;
      }
      </script>
      <form name="URLFORM" onSubmit="return gotoURL(this)">
      <input Type="text" value="http://" Name="address" size="30">
      </form>

Above example works in NN4.04 and MIE4.01 win 95.
Note, that browsers DONT ADD PAGE TO HISTORY  
IF PAGE NOT EXISTS! In case page5.html
not exists, you would have REPLACE effect.
In case page5 initially loaded to frameset OK
there will be no problems with it.
Just make at least empty HTML stubs for pages 2,3,4,5
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1273384
Well, if Kollegov is right it won't matter, but the code I showed you is the exact code you use to capture the enter press event.
Just put that code right into a script section on any document, and it will execute the handler function when you press enter and focus is on that document object.
The only pseudo code I had was this line:
  {parent.frames[whatever].location=processed str;
You should know how to do this line.  Just try my solution on a document, and replace that line with an alert and you'll see it work (only in IE 4 of course).

-Josh
0
 

Author Comment

by:emadgharavi
ID: 1273385
Thanks kollegov:

Glad to say, but that was exactly the problem.  The first document in frameE was written on the fly with document.write() method and for asome reason in IE it was behaving strange.

Also thanks to Jbirk for his persistence and very useful advice.
By the way Jbirk, I had tried your script and it works great. The only problrm is that while the cursor is in textbox area, nothing is captured -- ie you must focus outside of the form element to capture keystrokes with document.onkeypress.

Thank you gang!
0
 
LVL 8

Expert Comment

by:jbirk
ID: 1273386
Glad to hear that Kollegov figured this out (kind of frustrating with wierd problems like this isn't it?)

I believe adding this will capture the event when the mouse is over the textbox:
document.form_name.text_box_name.onkeypress=handler;
Keep in mind that this is still only IE 4.

-Josh
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question