2013-06-27 46 views
0
javascript:(
    function(){ 
     window.twttr = window.twttr || {}; 
     var D = 550, 
     A = 450, 
     C = screen.height, 
     B = screen.width, 
     H = Math.round((B/2)-(D/2)), 
     G = 0, 
     F = document, 
     E; 

     if (C > A) { 
      G = Math.round((C/2) - (A/2)) 
     } 

     window.twttr.shareWin = window.open(
      'http://twitter.com/share?text=test+e(l.href)+'&t='+e(d.title)','','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1'); 
     E = F.createElement('script'); 
     F.getElementsByTagName('head')[0].appendChild(E) 
    }()); 

这是代码,它应该打开twitter鸣叫窗口,并且里面必须填充页面的网址。然而,当在谷歌浏览器中用作按钮时,它什么也不做,通过从javascript中删除“?text =”,我得到了一个空白的推文页面,这不是我想要的。 那么如何解决它,所以它记下的网址和标题?像这样: 标题 - 网址这个Javascript的“获取URL和标题”有什么问题?

文本的URL编码

在此先感谢 “文本=?”。

回答

1

你缺少一个右撇号:

'http://twitter.com/share?text=test' 

与修复整个片段:

javascript:(function(){window.twttr=window.twttr||{};var D=550,A=450,C=screen.height,B=screen.width,H=Math.round((B/2)-(D/2)),G=0,F=document,E;if(C>A){G=Math.round((C/2)-(A/2))}window.twttr.shareWin=window.open('http://twitter.com/share?text=test'+e(l.href)+'&t='+e(d.title)','','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1');E=F.createElement('script');F.getElementsByTagName('head')[0].appendChild(E)}()); 

漂亮代码:

javascript:(
    function(){ 
     window.twttr = window.twttr || {}; 
     var D = 550, 
     A = 450, 
     C = screen.height, 
     B = screen.width, 
     H = Math.round((B/2)-(D/2)), 
     G = 0, 
     F = document, 
     E; 

     if (C > A) { 
      G = Math.round((C/2) - (A/2)) 
     } 

     window.twttr.shareWin = window.open(
      'http://twitter.com/share?text=test'+e(l.href)+'&t='+e(d.title)','','left='+H+',top='+G+',width='+D+',height='+A+',personalbar=0,toolbar=0,scrollbars=1,resizable=1'); 
     E = F.createElement('script'); 
     F.getElementsByTagName('head')[0].appendChild(E) 
    }()); 
+0

没有注意到,我还缺少+ '?' ,因为“?”是告诉它在里面写什么的变量。 – thethiny