Passing a dynamic link to a Bookmarking Site...

Discussion in 'JavaScript' started by danweav, Jul 19, 2010.

  1. #1
    I've written this simple code that writes the correct links for sending that particular pages details to the corresponding bookmaking sites...

      function getlink(site){
    	if (site=='facebook'){
    		window.open('http://facebook.com/share.php?u='+location.href+'&t='+document.title,'share','width=400, height=400, scrollbars=yes,resizable=yes')
    	}
    	if (site=='del'){
    		window.open('http://delicious.com/post?url='+location.href+'&title='+document.title+'&notes'+document.getElementsByName('description')[0].getAttribute('content'),'share','width=850, height=650, scrollbars=yes,resizable=yes')
    	}
    	if (site=='twitter'){
    		window.open('http://twitter.com/home?status='+document.title+' - '+location.href,'share','width=800, height=490, scrollbars=yes,resizable=yes')
    	}
    	if (site=='stumble'){
    		window.open('http://www.stumbleupon.com/submit?url='+location.href+'&title='+document.title,'share','width=850, height=600, scrollbars=yes,resizable=yes')
    	}
    	if (site=='digg'){
    		window.open('http://digg.com/submit?phase=2&url='+location.href+'&title='+document.title+'&bodytext='+document.getElementsByName('description')[0].getAttribute('content'),'share','width=950, height=550, scrollbars=yes,resizable=yes')
    	}
    	if (site=='google'){
    		window.open('http://www.google.com/bookmarks/mark?op=edit&bkmk='+location.href+'&title='+document.title+'&annotation='+document.getElementsByName('description')[0].getAttribute('content'),'share','width=950, height=550, scrollbars=yes,resizable=yes')
    	}
    	if (site=='techno'){
    		window.open('http://technorati.com/faves?add='+location.href,'share','width=950, height=550, scrollbars=yes,resizable=yes')
    	}
    	if (site=='reddit'){
    		window.open('http://reddit.com/submit?url='+location.href+'&title='+document.title,'share','width=950, height=550, scrollbars=yes,resizable=yes')
    	}
    	if (site=='myspace'){
    		window.open('http://www.myspace.com/Modules/PostTo/Pages/?u='+location.href+'&t='+document.title,'share','width=950, height=550, scrollbars=yes,resizable=yes')
    	}
    	if (site=='dzone'){
    		window.open('http://www.dzone.com/links/add.html?url='+location.href+'&title='+document.title,'share','width=950, height=550, scrollbars=yes,resizable=yes')
    	}
    }
    Code (markup):
    So above code will write the facebook link like this...

    http://facebook.com/share.php?u=http://www.domain.com?PARAM1=VALUE1&PARAM2=VALUE2&PARAM3=VALUE3&t=PAGE+TITLE
    Code (markup):
    The problem is... If the page that I'm trying to bookmark features url parameters (like the example above)... only part of the url is recognised by the bookmarking site... example...

    Actual Link...
    http://www.domain.com?PARAM1=VALUE1&PARAM2=VALUE2&PARAM3=VALUE3
    Code (markup):
    The BM Sites only reconise...
    http://www.domain.com?PARAM1=a
    Code (markup):
    I've noticed that sharethis.com rewrite their links like this...
    http://www.domain.com%3FPARAM1%3DVALUE1%26PARAM2%3DVALUE2%26PARAM3%3DVALUE3
    Code (markup):
    &=%26
    Equals=%3D
    ?=%3F

    Is there a simple way to rewrite the URL so that it can be used within a URL parameter?
     
    danweav, Jul 19, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    No, there's no need to rewrite the URL, the browser should do this automatically. I'm not sure if the problem is with your javascript, but it most likely is.
     
    Rainulf, Jul 19, 2010 IP
  3. danweav

    danweav Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can anyone elaborate on what might be wrong with the javascript please?
     
    danweav, Jul 20, 2010 IP
  4. ashishhbti

    ashishhbti Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Use encodeURIComponent javascript function ..

    encodeURIComponent(url)

    Thanks
     
    ashishhbti, Jul 21, 2010 IP