I just want to export a webpage loaded inside an iFrame. But I want to have action from an outer iFrame.
Here's my code to clarify things:
<html>
<body>
some contents here....
<div id="main">
<iframe id="myiframe" src="template/index.html"></iframe>
</div>
<a href="#" id="downloadLink">Export</a>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
function downloadInnerHtml(filename, elId, mimeType) {
var elHtml = document.getElementById(elId).innerHTML;
var link = document.createElement('a');
mimeType = mimeType || 'text/plain';
link.setAttribute('download', filename);
link.setAttribute('href', 'data:' + mimeType + ';charset=utf-8,' + encodeURIComponent(elHtml));
link.click();
}
var fileName = 'newlstter.html';
$('#downloadLink').click(function(){
downloadInnerHtml(fileName, 'main','text/html');
});
});
</script>
</body>
</html>
When I click the export
button the HTML file is exported and it will include the iFrame. But if I use these codes inside the inner HTML file it will export. But I need to export that current HTML page from the outter site. Exactly like my code above. But I just want to export only the inner HTML.
Can any one give me some suggestion for this? Note: Please I need jQuery or JS code, not PHP.
Thanks!
I suggest using an AJAX; the following fiddle returns just the HTML that you need: https://jsfiddle.net/yLL48one/2/
$.get( "/yLL48one/1/", function( data ) {
console.log( data );
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.