如何在当前选项卡中向后导航一步

How to navigate one step back in history in current tab?

本文关键字:导航 一步 选项      更新时间:2023-09-26

我正在开发一个Chrome扩展。在扩展页我有一个按钮。当按下这个按钮时,我想在当前打开的选项卡中导航一步回到历史,所以我希望这个按钮的行为像后退按钮。我在SO上看到了一些答案,但似乎没有一个适合我。如何做到这一点?

我有以下mainfest.

{
  "manifest_version": 2,
  "name": "Getting started example",
  "description": "This extension shows a Google Image search result for the current page",
  "version": "1.0",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": [
    "webNavigation",
    "history",
    "activeTab",
    "https://ajax.googleapis.com/"
  ]
}

和javascript文件

document.addEventListener('DOMContentLoaded', function() {
  var btn = document.getElementById('btnRestart');
  btn.addEventListener("click", function() {
    console.log('inside click');
    history.back();
    console.log('after back');
  }, false);
});

嗯,我还不能留下评论,但我得到了一个扩展带我回来使用这里显示的方法https://gist.github.com/greatghoul/8120275当然改变alert()与window.history.back()如果它不工作,首先重新打开你的chrome