I have looked and looked for an answer to this question. So I apologize in advance when the solution is very easy.
I want to take the url of the current page eg. http://www.example.com/example.html and put this in a link (among other uses) using javascript.
so it would look like this:
<a href"www.example.com/example.html"></a>
I’ve tried lots of things I know I need to use location.href but just can’t seem to get it to work.
This is the closest I got to getting it to work,:
<a href"javascript:write.location.href;"></a>
Thanks, sorry again. I’m new to JS and html.
J
Name your element with an ID, like:
<a id="pageLink"></a>and then when the document loads you can run this snippet:Or, with something like jQuery:
EDIT In response to your question in the comments:
I’m not sure I’m understanding you completely but if it’s fixed, then you’d simply concatenate to the href before setting it, e.g.