0

So in popup.html I got some links that works when I load it into Chrome, but when I append some links using forminput.js; the links are appended and it does work when I launch it from Notepad++ but fails to work when I load it into Chrome, dropdown.js and createtab.js both works fine and has nothing to do with this problem, they contain logic for opening tabs and handling dropdown menu. Thanks

popup.html

<body>
<form id="aform">
  URL:<br>
  <input type="text" name="URL" id="URL">
  <br>
  Bookmark Name:<br>
  <input type="text" name="bookmarkname" id="bookmarkname">
  <br><br>
  <input type="button" id="formsubmit" value="Submit">
</form> 
<div class="dropdown">
  <button class="dropbtn" id="dropdown">Links</button>
  <div id="myDropdown" class="dropdown-content">
    <a href="https://www.youtube.com">Youtube</a>
    <a href="https://www.amazon.com">Amazon</a>
    <a href="https://www.yahoo.com">Yahoo</a>
  </div>
</div>

<script src="forminput.js"></script>
<script src="dropdown.js"></script>
<script src="createtab.js"></script>

manifest.json

    {
    "name" : "Links",
    "version" : "1.0",
    "description" : "links 4 u",

    "manifest_version" : 2, 

    "browser_action": {
        "default icon":"icon.png",
        "default_popup":"popup.html"
    },

    "permissions": [
        "tabs",
        "storage"
    ]
}

forminput.js

    function retrieveFormData() {

            var URL = document.getElementById("URL").value;
            var Bookmarkname = document.getElementById("bookmarkname").value;
            var y = document.getElementById("myDropdown");
            var aTag = document.createElement('a');
            aTag.appendChild(document.createTextNode(Bookmarkname));
            aTag.href = URL;
            y.appendChild(aTag);
}


document.getElementById("formsubmit").addEventListener("click",retrieveFormData);
Bharat
  • 2,441
  • 3
  • 24
  • 36

1 Answers1

0

The popup is a separate document (see extensions architecture) that can't be navigated outside the extension's internal URL, which is chrome-extension://blablablabla/

You need to add target="_blank" attribute to all links or use tabs API if you want to open the links in current tab (requires "tabs" permission or, much better, "activeTab"):

chrome.tabs.update({url: 'https://www.google.com'});
wOxxOm
  • 65,848
  • 11
  • 132
  • 136