Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can i email the print version only 1

Status
Not open for further replies.

tango1948

Programmer
Dec 23, 2006
111
IL
Hi,
I have an html page which has print and screen versions using "@media print" and "@media screen", is it possible to email only the print version - (@media print, email)
Thanks for any help

David
 
I think the question is more like "given an html page, can I email it at all?".

Until you solve that one, let's not even bother complicating it with different CSS variations.

The best I can come up with requires server-side scripting to send the email (rather than doing it client-side). You could manipulate the HTML source to include just the CSS include you need (again server-side) using a regular expression or something.

No solution exists that will allow you to do this using merely javascript client-side.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Jeff thanks for your reply.
Would it not be possible when the (email) button is pressed to use innerHTML to compose the email content in html format?
 
So you get the innerHTML and you parse it using Javascript to make it contain all the right information that you want to send. That's not the hard part.

How will you send it? That's the kicker.

You need to go server-side to send (using the client-side mailto: isn't going to cut it due to the large(r) amount of data to be sent). So it makes more sense to do the whole thing server-side.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Mail clients are very different beasts to web browsers. Some don't play nicely with CSS so you are probably going to be fighting a losing battle trying to force a print CSS layout into an email.

Why not just send a plain text email? They tend to be quite printable and you won't have any compatibility problems along the way.

Besides, if you send an HTML mail then you should ensure that it is sent as a Multipart message which contains a text only version anyway.

Hey, I just cut your workload in half! :)

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Is it not possible to use the browsers eMail option to send a page that I create.
 
Is it not possible to use the browsers eMail option to send a page that I create.
Even if you could then think about what the "browser's email option" does.

Let's consider 2 popular browsers.

Internet Explorer.
It sends the email via the user's email client - be that Outlook, Outlook Express, whatever. The browser itself doesn't send anything. It throws the HTML from the page at the mail client, but whether that will work or not depends on the mail client - and more so how the mail looks to the recipient depends on their mail client.

Firefox.
This browser has an option to send a link. It doesn't send the page. But again it uses the user's email client to send a mail.

Even if you could use the browser's own mail command it wouldn't give you a consistent result and most likely won't do what you want anyway.


The best way to send mail from a webpage is via a server side script of some kind.

If you want to send HTML mail then make the HTML dead simple - retro even! Table layouts, font tags etc! Horrible but the only real way to get a remotely consistent result.

If you are sending HTML mail then you should send it as a Mutlipart message and include a plain text version. Again, server side scripts are the way to do this.


Finally, bear in mind that email is a text medium. It's a happy (hmm) coincidence that HTML is basically text. Consequently email has been hijacked for sending HTML mail. Whilst there isn't anything really wrong with this, you must take time to consider how you send the mail and the ramifications therein. What appears simple, isn't. Sadly many people overlook this.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top