在编写谷歌浏览器插件的时候,如果我在background.js中用chrome.tabs.update跳到我本地的页面,如下面这样
chrome.tabs.onCreated.addListener(function (tab) {
if( (tab.title =='新标签页' || tab.pendingUrl == 'edge://newtab/')){
console.log('内部执行1 edge');
chrome.tabs.update(tab.id, { url: 'static/HTML/ntab.html' });
}
if( (tab.title == '新建标签页' || tab.pendingUrl == 'chrome://newtab/')){
console.log('内部执行2 guge');
chrome.tabs.update(tab.id, { url: 'static/HTML/ntab.html' });
}
if(tab.pendingUrl == 'qqbrowser://newtab'){
console.log('内部执行3 QQ');
chrome.tabs.update(tab.id, { url: 'static/HTML/ntab.html' });
}
});
我要怎么在我跳去我本地的static/HTML/ntab.html后,返回浏览器默认的打开新标签页地址呢?
这样可以
ntab.html<br />
<button>返回</button>
<script src="back.js"></script>
document.querySelector('button').addEventListener('click', function () {
chrome.tabs.update({ url: 'chrome://newtab/' })
});
参考GPT和自己的思路:您可以在static/HTML/ntab.html中使用JavaScript中的history对象来实现返回上一页的功能。例如:
history.back();
这个方法会让您返回到上一页,即浏览器默认的打开新标签页地址。
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!