Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  70] [ 6]  / answers: 1 / hits: 15482  / 9 Years ago, mon, december 7, 2015, 12:00:00

So, Ive read through similar things but I still can't find an answer that applies more closely to what I'm doing. I am attempting to use JS to get the current page URL and append it to a social media sharing link like this:



<a href=http://reddit.com/submit?url=CURRENTPAGE.html; title=This is a post! target=_blank>


Using Javascript, I've managed to assign the current URL to a variable:



<script>
var x = window.location.href;
document.getElementById(smsharing).innerHTML = x;
</script></p>


And I made sure it worked by doing a test display of it. So what exactly is the proper method/syntax for actually putting 'x' in place of CURRENTPAGE.html???



I know this is a STUPID question, but I'm really stumped. Specifics help, because part of the problem is that I have precious little knowledge of JS. Thoughts?


More From » html

 Answers
75

This should do it:



<script>
baseurl=http://www.facebook.com?
function buildURL(item)
{
item.href=baseurl+window.location.href;
return true;
}
</script>
</head>
<body>
<a onclick=return buildURL(this) href=>Google</a>
</body>

[#64138] Friday, December 4, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
agustindejonm

Total Points: 738
Total Questions: 84
Total Answers: 84

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
agustindejonm questions
Fri, Jun 25, 21, 00:00, 3 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Sat, May 16, 20, 00:00, 4 Years ago
;