【问题标题】:Javascript windows.open errorJavascript windows.open 错误
【发布时间】:2013-04-22 06:46:47
【问题描述】:

我的页面末尾有以下代码。

<script>
$(".btn_fb").click(function() {
    window.open("http://www.facebook.com/sharer.php?u="+document.URL+"&amp;t=<%hdl_Title%>", "Facebook", "width=660,height=400,scrollbars=no;resizable=no");
    return false;
});    
$(".btn_tw").click(function() {
    window.open("http://twitter.com/home?status=<%hdl_Title%> "+document.URL+"", "Twitter", "width=660,height=400,scrollbars=no;resizable=no");
    return false;
});    
$(".btn_li").click(function() {
    window.open("http://www.linkedin.com/shareArticle?mini=true&amp;url="+document.URL+"&amp;title=<%hdl_Title%>;summary=<%hdl_Title%>", "LinkedIn", "width=660,height=400,scrollbars=no;resizable=no");
    return false;
}); 

$('.btn_go').click(function() {
    window.open("http://plus.google.com/share?url="+document.URL, 'Google Plus', 'width=660,height=500,scrollbars=no;resizable=no');
    return false;
});     
$(".btn_ma").attr("href", "mailto:?subject=<%hdl_Title%>&body=Hi%0D%0A%0D%0AI thought you may be interested in this: <%hdl_Title%> " + window.location); 

IE9 在遇到这部分脚本时会引发错误,我无法确定错误是什么。 FF 不会抛出错误。

<script>   
    $('.button_google_plus').click(function() {
        window.open("http://plus.google.com/share?url="+document.URL, 'Google Plus', 'width=660,height=500,scrollbars=no;resizable=no');
        return false;
    }); 
</script> 

注意:代码:

<%hdl_Title%>

是 CMS 中的一个参数集。

【问题讨论】:

  • 错误信息是什么
  • 您还应该对通过查询字符串传递的 URL 进行编码:window.open("http://plus.google.com/share?url=" + encodeURIComponent(document.URL), ...);
  • @ArunPJohny:错误消息是消息:无效参数。
  • @Phil - 感谢您的链接。我的问题有点不同,因为我有一些语义错误。

标签: javascript


【解决方案1】:

window.open() 方法的标题不能有空格,window 属性只能包含, 而不是;
试试这个

window.open("http://plus.google.com/share?url="+document.URL, 'GooglePlus', 'width=660,height=500,scrollbars=no,resizable=no');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-16
    • 2018-02-21
    • 2022-12-08
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    相关资源
    最近更新 更多