PHJCJO PHJCJO - 6 months ago 13
jQuery Question

Access nodes from an xml with in an iframe

I loaded an XML file to an iframe with the intention of accessing the xml nodes from java-script, using pure js or jquery with supporting cross browser.

<!DOCTYPE html>
<html>
<body>
<iframe id='contentHolder' src='../xml/BookList.xml'></iframe>
</body>
</html>

Answer

with jquery:

<iframe src="../xml/BookList.xml" id="contentHolder"></iframe>

<script>
$( "#contentHolder" ).load(function () {
   console.log("iframe loaded")
   console.log($( "#contentHolder" ).contents().find("body").text())
});
</script>

see the article on their website: https://api.jquery.com/contents/

Comments