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 推文窗口,里面必须填写页面的 url。但是,当用作 google chrome 中的按钮时,它什么也不做,并且通过从 javascript 中删除“?text =”,我得到了一个空白的推文页面,这不是我想要的。那么如何修复它以便写下网址和标题?像这样:标题 - 网址

文本的 url 代码是 "?text="

提前致谢。

4

1 回答 1

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)
    }());
于 2013-06-27T05:24:50.217 回答