Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
109 views
in Technique[技术] by (71.8m points)

javascript - chrome extension poup window.location change

I'm developing extension for browsers and i have a problem with Google Chrome. In manifest.json file i have declared default_popup page and in that page i have a button which will change window.location.href on click. The problem is when i click that button, popup page is not changing. How can i achieve that on Google Chrome? On Firefox is working well.

Here is the code

manifest.json

  "manifest_version": 2,
  "name": "NewExt",
  "version": "1.0",

  "description": "My best project",

  "icons": {
    "48": "icons/icon-48.png"
  },
  "browser_action": {
    "browser_style": true,
    "default_popup": "popup.html",
    "default_icon": {
      "48": "icons/icon-48.png"
    }
  }
}

popup.html

<!DOCTYPE html>
<html>
  <head> </head>
  <body>
    <button id="btn">Click</button>
    <script src="main.js" type="text/javascript"></script>
  </body>
</html>

main.js

function redirect() {
  window.location.href = "http://example.org";
  console.log("works");
}
document.getElementById("btn").addEventListener("click", function () {
  redirect();
});
question from:https://stackoverflow.com/questions/65938652/chrome-extension-poup-window-location-change

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...