Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “电子邮件当前页面”按钮在Chrome中不起作用_Javascript_Google Chrome - Fatal编程技术网

Javascript “电子邮件当前页面”按钮在Chrome中不起作用

Javascript “电子邮件当前页面”按钮在Chrome中不起作用,javascript,google-chrome,Javascript,Google Chrome,我在一个网站上有一段代码,可以通过电子邮件发送当前页面。它可以在Firefox上运行,但不能在Chrome上运行。我在谷歌上搜索了这个问题,但没有找到任何答案。我做错什么了吗 <script> function emailCurrentPage(){ // In comments, other things I've tried //window.location.href="mailto:?subject="+document.title+"&

我在一个网站上有一段代码,可以通过电子邮件发送当前页面。它可以在Firefox上运行,但不能在Chrome上运行。我在谷歌上搜索了这个问题,但没有找到任何答案。我做错什么了吗

<script>
    function emailCurrentPage(){
        // In comments, other things I've tried
       //window.location.href="mailto:?subject="+document.title+"&body="+escape(window.location.href);
       //document.location.href="mailto:?subject="+document.title+"&body="+escape(document.location.href);

        document.location="mailto:?subject="+document.title+"&body="+escape(document.location);
}
</script>
<button onclick="emailCurrentPage();">
    Send by email
</button>
谢谢。

更改您的功能:

window.location.href="mailto:?subject="+document.title+"&body="+encodeURI(document.location);

在最新版本的Chrome中,这个按钮对我来说似乎工作得很好@很奇怪,你的小提琴在我的Chrome版本中也能用。。。所以问题可能不是实际的代码,而是其他的东西。我只是不明白为什么它在FF中仍然有效。