?
Solved

can i specify an inner frame as a form target...in a popup?

Posted on 2003-02-25
17
Medium Priority
?
496 Views
Last Modified: 2008-01-09
A webpage i'm developing uses a standard form that interacts with a servlet.  The form has several submit buttons, each of which flags a different command (for good reasons, i can't split the form).

One of the form actions triggers the servlet to stream an excel file to the requesting page...the page content type is reset to application/excel.

The excel is streamed into a popup window (which i keep track of with a javascript variable).  My problem is, when the excel is streamed, the "closed" property of the window is set to "true", and i can no longer interact with the page by using the JS object.

As a result, i want to open an html page with a frame or iframe, and specify the FRAME as the target for the form post action.  Referencing a frame or iframe withing an external page is easy (windowObj.frames.myFrameId), but i have no idea how to hit a submit button on a source page, and stream the results into a frame on an external page.

The TARGET attribute of the form object can't be pointed to a frame reference, because it's a string.  I'm beginning to believe this is impossible without using a forwarding agent of some kind.
0
Comment
Question by:StrayDog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 5
17 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020067
if you know the name of the external window, and you know it is open, you can get a handle to it like this:

var hwnd = window.open( "", "nameOfThePopup" );
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020072
the drawback is that if the window is indeed closed, this will create a new, empty window by that name.
0
 

Author Comment

by:StrayDog
ID: 8020113
Thanks, but that's not quite the problem...if i declare:

var wnd = window.open('','results');
document.form.target.value = 'results';
...
<form method="post" action="mypage.htm">
   <submit, etc>
</form>

Then calling: wnd.close() will close the popup just fine.

**BUT**, if the action on the form triggers an excel spreadsheet, then wnd.close doesn't work anymore...the wnd object is closed by the browser, the MIME type is set to application/excel (i know this because wnd.closed returns true, even though the spreadsheet is still visible).

I need to be able to close the window from the parent, which is why i want to load the spreadsheet into an inner frame *on the popup*...but i don't know how.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Expert Comment

by:knightEknight
ID: 8020183
let me explain further ...

you can get the handle AFTER the window is open ...

<form method="post" action="mypage.htm" target="mypopup">
   <submit, etc>
</form>

then, when you want to close the window, do this:

var wnd = window.open('','results');
wnd.close();

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020185
oops, that should be:

var wnd = window.open('','mypopup');
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020193
or 'results' will work too, as long as the form target is also 'results'
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020204
you can even do it in one line:

window.open('', 'mypopup').close();
0
 

Author Comment

by:StrayDog
ID: 8020254
No, i CAN'T do that.
Under normal circumstances, that will work.  But i have a case where:
a)  a browser window is clearly visible
b)  the window was named from the parent
c)  the "closed" attribute of the popup object is TRUE, because
d)  excel has hijacked my window, so
e)  calling the close() function doesn't work

I know your solution works normally...to prove it, i just set the form action to http://www.google.com, watched the popup show a broken google page, and close it.  The exact same code, with the action redirected to an excel steaming servlet, breaks...i can no longer close the page.  This seems like a bug in IE, but i don't care.

What i want to know is how i can change the action on the form to a FRAME inside the popup window, instead of the popup window itself.  That will preserve the window object's status in the parent.
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 300 total points
ID: 8020352
it seems like you should just be able to set the target to the frame name in the popup

in the popup:

<html>
<body>
<iframe name='results' ... >
</iframe>
</body>
</html>


and in the parent, open the popup containing the iframe before submitting the form:

<form name='myform' target='results' action='mypage.htm' method='post'
    onsubmit='window.open("mypopup.htm","mypopup");return true;' >
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020362
in this case I used 'results' and 'mypopup' to refer to different frame/window objects.
0
 

Author Comment

by:StrayDog
ID: 8020369
here, take a look at these two files:

=============== test1.htm =======================
<html>

<head>
  <title>test1: parent window</title>
  <script type="text/javascript">
    var popup = null;
    function setPopup() {
      popup = open('test2.htm','someName','menubar=1,toolbar=1,location=1,directories=1,scrollbars=1,resizable=1,status=1,width=640,height=480');
      popup.focus();
      document.form.target = "someName";
    }
  </script>
</head>

<body>
  <form name="form" action="http://www.google.com" method="get">
    <input type="submit" name="submit" value="Popup" onclick="setPopup()">
    <input type="button" name="close" value="Close" onclick="popup.close();">
  </form>
</body>

</html>


==================== test2.htm ========================
<html>
<head>
 <title>test2: test1's popup</title>
</head>
<body>
  <iframe id="inner" frameborder="1" scrolling="no"
    width="400px" height="100px"
    marginwidth="0" marginheight="0">
  </iframe>
 this is stuff outside the frame.  i want the form action to load INSIDE the frame on the left!!
</body>
</html>


Now, i KNOW that the close button will close the popup...and that's exactly what you're telling me.  This is what i had to begin with :)

Assume that this DOESN'T work (and trust me, if test2.htm were actually an excel file streamed from a servlet, it would break...the popup.closed value is set to "true", and it's read-only so i can't touch it).  Now, i need a way to stuff the broken google output into the inner frame, instead of in the entire popup window.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020376
and leave off the src attribute of the iframe in the popup.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020384
give the iframe a name as well as an id.
0
 

Author Comment

by:StrayDog
ID: 8020432
Ok sorry, i just read your solution with the split naming convention (i was busy writing that post :D)

It looks good, i'll try it out and let you know.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020482
don't name the form "form" -- it is a javascript keyword
similarly, don't name your submit button "submit" because you overwrite the form's submit method.  (sorry, pet-peaves of mine)




test1.htm
=============================================


<html>

<head>
 <title>test1: parent window</title>
 <script type="text/javascript">
   var mypopup = null;
   function setPopup()
   {
     mypopup = open('test2.htm','mypopup','menubar=1,toolbar=1,location=1,directories=1,scrollbars=1,resizable=1,status=1,width=640,height=480');
     mypopup.focus();
     //document.myform.target = 'inner';
     return true;
   }
 </script>
</head>

<body>
 <form name="myform" action="http://www.google.com" method="get" target="inner" onsubmit='return setPopup();' />
   <input type="submit" name="btnSubmit" value="Popup" >
   <input type="button" name="btnClose" value="Close" onclick='window.open("","mypopup").close();' />
 </form>
</body>

</html>



test2.htm
============================================


<html>
<head>
<title>test2: test1's popup</title>
</head>
<body>
 <iframe id="inner" name="inner" frameborder="1" scrolling="no"
   width="400px" height="100px"
   marginwidth="0" marginheight="0">
 </iframe>
this is stuff outside the frame.  i want the form action to load INSIDE the frame on the left!!
</body>
</html>
0
 

Author Comment

by:StrayDog
ID: 8020525
That solution works :)

It's ugly, and a hack, but it works now.  I'll change the popup to remove the scrollbars and borders, and the users will think the iframe's scrollbars are the window's scrollbars...from a UI perspective it will be fine.

Thanks for the prompt help, and the syntax tips too.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 8020559
thanks for the A!  glad to help.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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

770 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