tags:

views:

139

answers:

3

I swear I had this working last week, but... Does anyone know how to get same-page hrefs working within an email? I'm using this format;

<a href="#targetelement">quicklink</a>

...

<div id="targetelement">Hello there</div>

Which works in a standard webpage naturally, but it doesn't do anything when viewed in an email client (tested in Thunderbird and Gmail so far). Is same-page linking even possible within an email? If not, are there alternative methods?

UPDATE:
Using an id actually does work in Thunderbird, unless the email has been forwarded, then it stops working. id doesn't work in Gmail, name doesn't work in either.

+2  A: 

Try this now. :)

<a href="#targetelement">quicklink</a>

...

<a name="targetelement">Hello there</a>
echo
Why would this work when an id wouldn't? Email clients generally use the same rendering engines as browsers (Thunderbird uses Gecko and GMail uses … whatever browser the use uses). (OK, I can see why it **might** work in GMail, it depends on what Google do to sanitize the HTML, but desktop clients?)
David Dorward
@MatW. Are u sure the mail is an HTML ?
echo
@raj Erm... No. Actually IDs can even override names. There's no real reason to use the name attribute outside of forms anymore (certainly not for anchors). HTML5 drops the name attribute on anchors completely, I think. See http://stackoverflow.com/questions/484719/html-anchors-with-name-or-id also http://www.w3.org/TR/REC-html40-971218/struct/links.html#h-12.2.3
Alan
oh! thank you.. that was new to me. :)
echo
Sry, deleted my earlier comment - I hadn't paid enough attention to your code and wasn't using an <a> tag. That works in Gmail, but not Thunderbird. Gmail wants name and an <a> tag as a target, Thunderbird wants id.
MatW
A: 

That would wholly depend on the mail client (desktop or web based), different clients use different rulesets and engines for parsing and displaying email so there is no definitive answer.

code_burgar
Rather than say there isn't one answer for all, you could at least illustrate an answer to *one* of the clients mentioned in my question.
MatW
@MatW: Since your question was not "How do I make this work in one of these two email clients?" but included wording like "tested in Thunderbird and Gmail **so far**" it did not seem that you wanted a quick fix for one of the available clients but an universal solution.
code_burgar
Fair enough, but then why take the time to type a non-answer?
MatW
A: 

Why not try

<a href="#targetelement">quicklink</a>

...

<a name="targetelement" id="targetelement">Hello there</a>

In the same link, not nice - but might get it to work in several clients.

dikjones