|
|
 |
| Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

July 16th, 2007, 12:26 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Location: Chesterfield, MO, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to Get XML Document from iFrame
I am having trouble getting the xml object out of an iFrame. I'm using an iFrame to upload a document, which does xmlhttprequest doesn't seem to support. I'm trying the following script, which works great in FireFox but not in IE.
I have tried creating an XML document but could not figure out how load the contents using the a script I found at http://www.quirksmode.org/dom/importxml.html but I could not figure out how to load the contents of my iFrame into the xmlDoc created using the script there.
What can I do to get IE to recognize that the source of the iFrame is an XML document?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="/js/ajaxobject.js"></script>
<script type="text/javascript">
function showContent(i) {
var theXML = i.contentWindow.document;
var errors = new Array()
var count = 0;
xml_errors = theXML.getElementsByTagName("error");
//check if any errros were returned
if(xml_errors.length>0) {
//loop through those errors
for(i=0;i<xml_errors.length;i++) {
//and if there is any data to display
if(xml_errors[i].firstChild) {
//assign it to the errors array.
errors[i] = xml_errors[i].firstChild.nodeValue;
count++;
}
}
}
if(errors.length) {
alert(errors[0]);
}
else {
alert("You're golden");
}
}
</script>
</head>
<body>
<p>I Frame</p>
<iframe id="iFrame" width="400" height="500" src="xml.php" onload="showContent(this)"></iframe>
</body>
</html>
And the XML src file is
Code:
<?PHP
header("content-type:text/xml");
echo '<?xml version="1.0" encoding="utf-8"?>' ;
?>
<stuff>
<name>Robbert</name>
<name>Kelly</name>
<name>Jonathon</name>
<name>Carl</name>
<error>Uh Oh</error>
</stuff>
I changed
|

July 16th, 2007, 11:39 PM
|
|
Authorized User
|
|
Join Date: Jun 2007
Location: Tehran, Tehran, Iran.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi rvanandel
The 'document' object in IE is not an xml document. It's a DHTML document and has some useful methods and properties to manipulate HTML document dynamically. If you need to access loaded document as a DOM document, you can use 'XMLDocument' property of this object. Meaning, you should change your code to something like this :
var theXML = i.contentWindow.document.XMLDocument;
Ehsan Zaery Moghaddam
|

July 17th, 2007, 10:23 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Location: Chesterfield, MO, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you, that did the trick.
|

May 30th, 2008, 01:43 AM
|
|
Registered User
|
|
Join Date: May 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Very great!!!!!!!
|

April 9th, 2009, 07:53 PM
|
|
Registered User
|
|
Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by zaerymoghaddam
The 'document' object in IE is not an xml document. It's a DHTML document and has some useful methods and properties to manipulate HTML document dynamically. If you need to access loaded document as a DOM document, you can use 'XMLDocument' property of this object. Meaning, you should change your code to something like this :
var theXML = i.contentWindow.document.XMLDocument;
|
In IE7, the line above throws an "Access Denied" error.
|

April 10th, 2009, 04:04 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,045
Thanks: 1
Thanked 32 Times in 31 Posts
|
|
This can happen if the iframe's domain and the main window are not the same or even if they are being accessed via a different protocol.
|

April 10th, 2009, 05:24 AM
|
|
Registered User
|
|
Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by joefawcett
This can happen if the iframe's domain and the main window are not the same or even if they are being accessed via a different protocol.
|
Yah that's what was going on... fortunately I found another way to accomplish my end goal. 
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |