I've searched through the other questions and have tried the suggestions but the answers do not seem to be working as I require.
I am retrieving emails from a database table and showing the body of the email within an iframe. I then need to fetch the html of the body of the email within a javascript file.
Code I have tried:
var body = $('#email-body').contents().find('html').html();
RETURNS: <head></head><body></body>
var body = '<?php echo $email->body;?>';
RETURNS: Invalid or unexpected token
(most likely due to the linebreaks the HTML has within it.)
It seems like the first option should work but it isn't pulling in the full contents as requested.
--EDIT--
As per comments, I attempted the following:
var iframe = document.getElementById('email-body');
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
var body;
if (iframeDocument) {
body = iframeDocument.documentElement.outerHTML;
}
RETURNS: <html><head></head><body></body></html>
-- EDIT 2 --
Iframe is populated as so:
<iframe id="email-body" src="/api/emails/email/{{{ $email->id }}}/body" onload="resizeIframe(this)"></iframe>
The email I am testing this with:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
</head>
<body>
<h2>Testing</h2>
<div>And again.</div>
</body>
</html>