如何使用javascript创建书签按钮?

时间:2022-04-24 01:23:03

How to create a bookmark button that sends the whole page as email .

如何创建将整个页面作为电子邮件发送的书签按钮。

4 个解决方案

#1


HTML content of a page is a bit harder to send, you can use this to send the page's text in an email like this -

页面的HTML内容有点难以发送,你可以使用它来发送这样的电子邮件中的页面文本 -

if (document.all)
    window.open("mailto:email@email.com?body=" + document.body.innerText); //For IE
else
    window.open("mailto:email@email.com?body=" + document.body.textContent); //For FF et al.

The bookmark will be -

书签将是 -

"javascript:if (document.all) window.open('mailto:email@email.com?body=' + document.body.innerText); else window.open('mailto:email@email.com?body=' + document.body.textContent);"

EDIT: For this to work, you'll have to create a link, and you'll have to right-click it and click "Add to Favorites".

编辑:要使其工作,您必须创建一个链接,您必须右键单击它并单击“添加到收藏夹”。

<a href="javascript:if (document.all) window.open('mailto:email@email.com?body=' + document.body.innerText); else window.open('mailto:email@email.com?body=' + document.body.textContent);">Bookmark This</a>

#2


I played with your question a little bit, done it with jquery ($('html').html()), and everything seemed fine for a moment.. BUT.. after I tried to email the whole content it didn't work either. When I got why it did not work I laughed - url too long, dude, software won't open it. Tested even on hard-coded string - short content opened the mail client fine, long did not.

我用你的问题玩了一下,用jquery($('html')。html())完成它,一切似乎都很好..但是......在我试图通过电子邮件发送整个内容后它没有工作要么。当我知道为什么它不起作用时我笑了 - 网址太长,老兄,软件不会打开它。甚至在硬编码的字符串上测试 - 短内容打开邮件客户端很好,很久没有。

Forgetaboudit.

If you want to read the html with javascript so hard, you can do it, but you have to send it via post to your server and mail it from there. Cheerz

如果你想用javascript阅读html这么难,你可以做到,但你必须通过邮件发送到你的服务器并从那里发送邮件。 Cheerz

ps. try with some test short html content and then with a whole casual webpage

PS。尝试使用一些测试简短的html内容,然后使用整个休闲网页

$(document).ready(function(){           
        $("#testlink").click(function() {
            $('#trick').text($("html").html().replace(/[\r\n]+/g, "%0A"));
            window.open('email@email.com?body='+$('#trick').html(), 'email', '');
        }); 
    }); 

#3


I know I'm bit late for this ;-) but try the following page. Its the perfect solution to your requirement: http://solutions.weblite.ca/emailwebpage/

我知道我有点迟到了;-)但是请尝试以下页面。它是满足您需求的完美解决方案:http://solutions.weblite.ca/emailwebpage/

#4


Put something like this within the head section of your HTML document, or better yet, skip the script tags and

将这样的内容放在HTML文档的head部分中,或者更好的是,跳过脚本标记和

put it in an external file and link to it in the head section instead:

把它放在一个外部文件中,然后在head部分链接到它:

<script language="JavaScript" type="Text/Javascript"><!-- // 
var url = " "; //u can add ur url
var pageName = "Client side programming"; 
function bookmark() { 
if (window.external) { 
window.external.AddFavorite(url, pageName)   
} 
else { 
alert("Sorry! Your browser doesn't support function. 
Use the bookmark option in your browser instead."); 
} 
} // --></script>

And this somewhere in the body section of your HTML document:

这是HTML文档正文部分的某个地方:

<input type="button" name="Bookmark this page" onclick="bookmark()" />

or...

Simple link:
<a
href="javascript:bookmark()">Click here to bookmark this page
</a>

#1


HTML content of a page is a bit harder to send, you can use this to send the page's text in an email like this -

页面的HTML内容有点难以发送,你可以使用它来发送这样的电子邮件中的页面文本 -

if (document.all)
    window.open("mailto:email@email.com?body=" + document.body.innerText); //For IE
else
    window.open("mailto:email@email.com?body=" + document.body.textContent); //For FF et al.

The bookmark will be -

书签将是 -

"javascript:if (document.all) window.open('mailto:email@email.com?body=' + document.body.innerText); else window.open('mailto:email@email.com?body=' + document.body.textContent);"

EDIT: For this to work, you'll have to create a link, and you'll have to right-click it and click "Add to Favorites".

编辑:要使其工作,您必须创建一个链接,您必须右键单击它并单击“添加到收藏夹”。

<a href="javascript:if (document.all) window.open('mailto:email@email.com?body=' + document.body.innerText); else window.open('mailto:email@email.com?body=' + document.body.textContent);">Bookmark This</a>

#2


I played with your question a little bit, done it with jquery ($('html').html()), and everything seemed fine for a moment.. BUT.. after I tried to email the whole content it didn't work either. When I got why it did not work I laughed - url too long, dude, software won't open it. Tested even on hard-coded string - short content opened the mail client fine, long did not.

我用你的问题玩了一下,用jquery($('html')。html())完成它,一切似乎都很好..但是......在我试图通过电子邮件发送整个内容后它没有工作要么。当我知道为什么它不起作用时我笑了 - 网址太长,老兄,软件不会打开它。甚至在硬编码的字符串上测试 - 短内容打开邮件客户端很好,很久没有。

Forgetaboudit.

If you want to read the html with javascript so hard, you can do it, but you have to send it via post to your server and mail it from there. Cheerz

如果你想用javascript阅读html这么难,你可以做到,但你必须通过邮件发送到你的服务器并从那里发送邮件。 Cheerz

ps. try with some test short html content and then with a whole casual webpage

PS。尝试使用一些测试简短的html内容,然后使用整个休闲网页

$(document).ready(function(){           
        $("#testlink").click(function() {
            $('#trick').text($("html").html().replace(/[\r\n]+/g, "%0A"));
            window.open('email@email.com?body='+$('#trick').html(), 'email', '');
        }); 
    }); 

#3


I know I'm bit late for this ;-) but try the following page. Its the perfect solution to your requirement: http://solutions.weblite.ca/emailwebpage/

我知道我有点迟到了;-)但是请尝试以下页面。它是满足您需求的完美解决方案:http://solutions.weblite.ca/emailwebpage/

#4


Put something like this within the head section of your HTML document, or better yet, skip the script tags and

将这样的内容放在HTML文档的head部分中,或者更好的是,跳过脚本标记和

put it in an external file and link to it in the head section instead:

把它放在一个外部文件中,然后在head部分链接到它:

<script language="JavaScript" type="Text/Javascript"><!-- // 
var url = " "; //u can add ur url
var pageName = "Client side programming"; 
function bookmark() { 
if (window.external) { 
window.external.AddFavorite(url, pageName)   
} 
else { 
alert("Sorry! Your browser doesn't support function. 
Use the bookmark option in your browser instead."); 
} 
} // --></script>

And this somewhere in the body section of your HTML document:

这是HTML文档正文部分的某个地方:

<input type="button" name="Bookmark this page" onclick="bookmark()" />

or...

Simple link:
<a
href="javascript:bookmark()">Click here to bookmark this page
</a>