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\n
the following code is written
\n\n\n<html><head><title></title>
\n
\n <script>
\n function iFrameOn() {
richTextField.document.designMode = 'On';
\n }
\n function export_Data() {
\n var n = document.getElementById(\"richTextField\");
\n var innerdoc = n.contentDocument || n.contentWindow.document;
\n var input = innerDoc.getElementsByTagName('body').text;
\n var zip = new JSZip();
\n zip.add(\"hello1.html\", \"\"+input);
\n zip.add(\"hello2.js\", \"this is just a simple file\");
\n content = zip.generate();
\n location.href=\"data:application/zip;base64,\" + content;
\n </script>\n </head>
\n <body>
\n <iframe name=\"richTextField\" id=\"richTextField\" class=\"form-control\" style=\"height:100%; word-wrap:break-word;\">
\n <button onclick=\"export_Data()\" name=\"export\">Export information</button>
\n </body>
\n </html>
Please Help me out this problem
\n","author":{"@type":"Person","name":"user3857603"},"upvoteCount":0,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"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.
\n\nvar n = document.getElementById(\"richTextField\");\nvar innerdoc = n.contentDocument.body.innerHTML;\n
\n","author":{"@type":"Person","name":"madhu"},"upvoteCount":0}}}Reputation:
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
Upvotes: 0
Views: 147
Reputation: 242
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;
Upvotes: 0