0

Based on some other code I found from this site (This Question here - Get URL and save it | Chrome Extension) I was wondering on how to display the URL of a current page in a input box. My coding is below

<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<script>
    chrome.tabs.getSelected(null, function(tab) {
        document.getElementById('currentLink').innerHTML = tab.url;
      });
</script>
</head>
<body>
<div class="links">
<div id="currentLink">Getting Current URL...</div>
<input type="text" id="currentLink" value="Loading...">
</div>
</body>
</html>

(I've cut some features out). But my question is, how can I get the URL to display in the input box, it displays when I use "div id" but not when I use "input id" any ideas why?

Community
  • 1
  • 1
itsdaniel0
  • 1,059
  • 3
  • 11
  • 28

1 Answers1

1

You have to set the value attribute of inputs.

document.getElementById('currentLink').value = tab.url;
abraham
  • 46,583
  • 10
  • 100
  • 152