How to write in 'mailto' body link to current page

前端 未结 4 1814
孤城傲影
孤城傲影 2020-12-16 01:56

I have mailto button in all pages of my site and I want to write reference to that page in e-mail body.

In one page I can have



        
4条回答
  •  醉梦人生
    2020-12-16 02:43

    With Javascript, you utf-8-percent-encode the subject and body hfvalues using encodeURIComponent() on a UTF-8 page.

    
    
        
            
            
            
        
        
            

    Email link to this page

    If you're doing this server-side, you can just build the mailto link and emit it as the href attribute value. Then, you won't need JS at all.

    I assume ASP has some URI encoding functions that work like encodeURIComponent().

    You can also view the source of my mailto URI composer page as another example.

    You an also take a look at http://shadow2531.com/opera/testcases/mailto/mailto_uri_scheme_idea.html#send_link_by_mail and my mailto URI syntax validator.

    For the < and > that I encase the URI in, in the JS code above, see "Appendix C. Delimiting a URI in Context" of RFC3986 for why.

    Also, instead of window.location.href, you can use window.location or document.location.href or document.location. I normally use "document.location".

    For why you use a Javascript URI instead of an onclick attribute, see this answer.

    Also note that in the JS URI in the code above, I wrapped the code in an anonymous function. That's not necessary in this case because the function doesn't return anything that would change the document when you click. But, it's to just do it all the time for good measure.

    See my Javascript URI compose to help with creating javascript URIs.

提交回复
热议问题