ChathinduSL ChathinduSL - 1 month ago 10
HTML Question

Add current browser URL into HTML hyperlink

I am new to "Stack OverFlow".. I am making a chrome extension.
I want to add current url into html link..

See this...

<html>
<body>
<a href="https://www.google.com/search?q=**Current URL**">Search</a>
</body>
</html>


add your answer code into my code and give me full code please!!! i am new guy to html(js,css)

Can you help me please????

Thank You!

Answer

[The snippet will throw an error, but window.location is what you are looking for]

Set an ID to your anchor tag. then do this:

var link = document.getElementById("demo");
link.href = "https://www.google.com/search?q=" + window.locatoin;
<a id="demo" href="https://www.google.com/search?q=**Current URL**">Search</a>