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)
    }());

This is the code, it is supposed to open the twitter tweet window , and inside it must be filled with the url of the page. however , when used as a button in google chrome , it does nothing , and by removing the "?text=" from the javascript , I got a blank tweet page which isn't what I want. so how can fix it so it writes down the url and title? like this: Title - Url

the url code of the Text is "?text="

thanks in advance.

maqjav
  • 2,310
  • 3
  • 23
  • 35
thethiny
  • 1,125
  • 1
  • 10
  • 26

1 Answers1

1

You're missing a closing apostrophe:

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

entire snippet with fix:

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)}());

pretty code:

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)
    }());
Matthew Graves
  • 3,226
  • 1
  • 17
  • 20
  • didn't notice, I was also missing +'?' , since "?" is the variable that tells it what to write inside. – thethiny Jun 27 '13 at 05:34