0

i am having the link like

<a href="http://twitter.com/home/?status='.$markme_ddesc.'" onclick="OpenPopup(this.href); return false">Click Here to See Popup</a>

for bookmarking the article clicked to twitter .. The above one just add the articles message to twitter.. But i am trying to add my article link also to twitter,.. so i am using the location.href but its not working tat is its not showing me the articles site name..

THe below is the one i tried..

<a href="http://twitter.com/home/?status=\'+encodeURIComponent(location.href)+\'-'.$markme_ddesc.'" onclick="OpenPopup(this.href); return false">Click Here to See Popup</a>

Thanks i advance.. Help me to get out of this...

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
useranon
  • 29,318
  • 31
  • 98
  • 146
  • http://stackoverflow.com/questions/2591282/href-link-with-onclick-event - Duplicate of your own question? – Prutswonder Apr 08 '10 at 06:21
  • here in this post i have been discussing on EncodeURI component .. In the previous post i was searching for Onclick window open but i didnt find the correct solution .. SO i find the new way to use the link in the href itself with popup function .. But i am not aware of using encodeURI – useranon Apr 08 '10 at 06:27
  • Ok, sorry about that, didn't have my morning coffee yet. ;-) – Prutswonder Apr 08 '10 at 06:31

2 Answers2

2

It seems that you're using PHP, so you could use

'<a href="...' . urlencode(curPageURL()) . '-' . $markme_ddesc . '...'

where curPageURL is a custom function to get the full URL. (Or use $_SERVER['REQUEST_URI'] if the domain is not needed.)


But if you really need to attach the URL from client side, you need to use Javascript.

<a id="xyz" href="http://twitter.com/home/?status=@PLACEHOLDER@-'.$markme_ddesc.'" … >
...

// onload:
var xyz = document.getElementById('xyz');
xyz.href = xyz.href.replace(/@PLACEHOLDER@/g, encodeURIComponent(location.href));

Of course this will fail if the client doesn't enable Javascript.

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
1

You can try this:

<a href="http://twitter.com/home/?status=" desc="<?php echo $markme_ddesc; ?>" onclick="OpenPopup(this.href,this.desc); return false">Click Here to See Popup</a>

<script>
   function OpenPopup(href,desc){             
        var url = href + encodeURIComponent(location.href) + '-' + desc;
        //show popup here...
   }
</script>
jerjer
  • 8,694
  • 30
  • 36