• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Servlet writes to iFrame...unable to read contents in IE7

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a form with action -> servlet and target -> iframe. The onload event for the iframe is set to a function that simply reads the text content of the frame:
[
<form method="post" src="MyServlet" target="uploadFrame" enctype="multipart/form-data" id="mainUploadForm">
....
</form>
<IFRAME id="uploadFrame" onload="resultUpload()" style="display:inline" name="uploadFrame" ></IFRAME>
<script>
document.getElementById("uploadFrame").onload = function() {doShowFrameContent(); }
</script>
]

Servlet processes form data and writes some text data (using response.writer) into the target/response:
[
...MyServlet code. doing some JSON stuff..
resp.getWriter().println(jsonStringer.toString());
]

Original calling page reads the iframe contents and displays text in an alert message.

Works fine in Firefox.

In IE7, data is written to the iframe (right-click on iframe, select "View Source", and I see the data in notepad).
But when I access the data, it returns empty html.

[
right-click on frame, and I see JSON data: {"result":"true","validDevices":0,"errorDevices":0,"companyDupes":26,"updatedDevices":0}
however, jscript code: alert(document.getElementById('uploadFrame').contentWindow.document.documentElement.outerHTML );
returns: <HTML><HEAD></HEAD><BODY> </BODY></HTML>
]

Note: I've used innerHTML as well, with the same result.

How can I access the {"result".....} data written to that iframe? "View Source" is doing it, how can I?

This is driving me nuts!!! Help!!!


 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan, you are registering two methods on the onLoad event of the frame. 1) resultUpload() and 2) function() {doShowFrameContent(); }

Now it would be great if you could give us code for these two methods and what you are doing in them. Can you see the text as it is in Firefox i.e. are you seeing this in firefox

{"result":"true","validDevices":0,"errorDevices":0,"companyDupes":26,"updatedDevices":0}
 
Dan Donahue
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, Ankit

The discrepency between onload event function names was a typo...I was trying to make the code a little clearer in my post by giving the function name something more illustrative. The onload function is called "resultUpload()" in all cases.


However, I think I found the problem...or at least a workaround. I found some information (I do not have the reference here) about the "target=" attribute in forms. Apparently, if you have something like I have, that is a target with NO extension, (target='uploadFrame'), then IE becomes confused and is unable to interpret the response output correctly. IE uses the extension on the target name to determine how to handle any response text. Without an extension, IE makes (poor) assumptions.

When I changed the name of the iframe from 'uploadFrame' to 'uploadFrame.html', and change my form tag to include target='uploadFrame.html' , then I was able to see the expected response output in the frame in both IE and Firefox. (Firefox had always worked as expected.)
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic