I’m trying to share personal web pages to any number of the social utilities (i.e. Facebook) out there now. But instead of trying to hard-code every single page url into the “Share to…” code, I was trying to get the page’s url automatically detected and inserted using Javascript. The “Share to…” code and Javascript’s “Detect Current Url” code work correctly independent of each other… I just can’t make them work together. Thoughts?
Below is what I ended up with:
[CODE]
<script type=”text/javascript”>
function currentUrl()
{
return(document.location);
}
function facebook(T, C, U, L)
{
var targetUrl = ‘http://www.facebook.com/sharer.php?u=$document.write(currentUrl())&t=$Title of Page&’ + ‘t=’ + encodeURIComponent(T)
+ ‘&c=’ + encodeURIComponent(C) + ‘&u=’ + encodeURIComponent(U) + ‘&l=’ + L;
window.open(targetUrl);
}
</script>
<a href=”javascript:facebook(‘Testing Post To Facebook’, ‘<p>Testing 1… 2… 3…<i>4… 5…. 6…</i></p>’, ‘document.write(currentUrl())’ &t=$Title of Page&’, 3)”>
<img src=”link-facebook.gif” border=”0″ alt=”Post to Facebook!” /></a>
“document.write(currentUrl())” inside the “a href” tag seems to be where the whole thing falls apart as actual urls work perfectly.