views:

20

answers:

5

In a new app, I'm building, I want to display an html email in a table in the browser.

The issue is that the html emails are changing the background color of my webpage and at times ends an html table I am using to display multiple emails.

The emails usually contain full html, body, div, and table tags. A normal occurrence is an body bgcolor"ff0000" which turns my entire app's background red.

Is there a way to combat this or do I have to code it to take out the html tags.

Also, I tried showing the email code in a iframes, but to no avail. it actually didn't display the code at all, just a blank iframe box.

<iframe>Body of html email here</iframe>

I'm sure I'm missing something simple - any help would be appreciated.

Btw, the email html is being held in a php string.

+1  A: 

what you can do is use javascript to inject the HTML of the email into the iFrame. The reason it changes your backgrounds is because you've got global styles in the stylesheet for the email, and they are getting applied to the rest of the page.

$('#loader_frame')[0].contentDocument.body.innerHTML = YOUR HTML
Anatoly G
So in jquery to input the html email, I would use $('#47').append('<?php echo $emailmessage; ?>'); for use with <iframe id="47"></iframe> - this would solve the issue? Also, can you send me a link or two to read up on global styles and help understand the issue?
Bob Cavezza
iframe is unlike normal dom elements, as you cannot append to it, what you need to do is access its contentDocument property. as far as global styles, any css doc will do. i updated my example for jquery
Anatoly G
Awesome, got it to work with a static example, but I'll need to put in some extra work to make it work for the dynamic app I'm building. Thanks!
Bob Cavezza
A: 

try to use chrome inspect element to to turn off some css feature and identify what element cause the problem and edit in css

wizztjh
A: 

to use iframe's you need to save the email as an HTML page and put a link to that in the iframe's src attribute.

The other way as you've pointed out is to remove the html and body tags. But you'll also need to remove the background styles.

One other thing to try is to make your styles from the parent page always take precedence.

try

body { background:lightgreen !important; /* important will override styles that come later with the same specificity */ }
Moin Zaman
A: 

The content inside the tag is displayed if the browser doesn't support iframes. To use the iframe correctly, you should set the src attribute:1

<iframe src ="html_intro.asp" width="100%" height="300">
  <p>Your browser does not support iframes.</p>
</iframe>

In practice, you could have this src attribute be a url that retrieves the body of the email. For example:

<iframe src="getemail.php?id=12345" width="100%" height="300"></iframe>

Where your getemail.php script takes the requested id and returns the html results which are displayed in the frame.

Bob Baddeley
I think the issue here is that some emails may contain private information and I would want to create a publicly viewable page for each email - even if I did create the email and delete the emails within the application itself, I still don't think it'd be a great idea.
Bob Cavezza
oh, I agree completely. Your getemail.php script should certainly verify the session authentication and permission of the user and do exactly the same checks that it does for the main page.
Bob Baddeley
A: 

i would use an iframe in this case too - the problem is you're using it wrong (the code in the tags is a fallback for old browsers):

<iframe src="yoursite.com/youremail.html" width="600" height="600" name="emailFrame">
  <p>Sorry, your Browser can't display iFrames</p>
</iframe>
oezi