get the content as well tags of the editable area from iframe editable
i have created a small editor where i have done a few commands as an example font formatting and
alignment etc so it is working fine in the browsers but i want to export the data which is written
in the editable area while i tried to fetch the data inside the editable iframe but it gives me an error.
error message: Uncaught ReferenceError: innerDoc is not defined
the following code is written
<html><head><title></title>
<script>
function iFrameOn() {
richTextField.document.designMode = 'On';
}
function export_Data() {
var n = document.getElementById("richTextField");
var innerdoc = n.contentDocument || n.contentWindow.document;
var input = innerDoc.getElementsByTagName('body').text;
var zip = new JSZip();
zip.add("hello1.html", ""+input);
zip.add("hello2.js", "this is just a simple file");
content = zip.generate();
location.href="data:application/zip;base64," + content;
</script> </head>
<body>
<iframe name="richTextField" id="richTextField" class="form-control" style="height:100%; word-wrap:break-word;">
<button onclick="export_Data()" name="export">Export information</button>
</body>
</html>
Please Help me out this problem
If it is on the same domain, try this. It won't let you access iframe contents if the iframe is of a different origin than the window that you are viewing.
var n = document.getElementById("richTextField");
var innerdoc = n.contentDocument.body.innerHTML;
链接地址: http://www.djcxy.com/p/82586.html