views:

41

answers:

2

hi ,

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...

+2  A: 

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.

KennyTM
My 5 hrs risk in solving the above error came to an end.. Thank you :)
Aruna
+1  A: 

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