更改Chrome扩展程序标签标题 [英] Change Chrome extension tab title
问题描述
我的Chrome扩展程序使用API创建标签页
My Chrome extension create a tab using the API
chrome.tabs.create({
'url': other_extension_url
})
URL是另一个扩展名的URL,如下所示:
The url is the the url of another extension and looks like:
chrome-extension://ext_id_goes_here/url
我想更改新创建的标签的标题( document.title
).
I would like to change the the title of the newly created tab (document.title
).
我尝试使用内容脚本来执行此操作,但据我所知,无法使用内容脚本来访问看起来像 chrome-extension://
I tried to do it using content script but as far as I understand there is no way to use content script with url that looks like chrome-extension://
还有其他方法吗?
推荐答案
这是一种实现方法.
<html>
<head>
<title>My title</title>
</head>
<body style="margin:0;padding:0;overflow:hidden;">
<iframe style="width:100%;height:100%;" src="chrome-extension://extension_id/page.html"></iframe>
</body>
</html>
请注意,我尚未在扩展HTML中尝试过此操作,但它确实在html file://中起作用,但在iframe中打开了扩展页面.
Note I haven't tried it from within an extension html but it did work from a html file:// opening an extension page in the iframe.
基于此,您可以有一个包装器"页面,用于接收标题和iframe网址作为url参数,并更新其DOM来更改标题和iframe src.
Based on this, you can have a single "wrapper" page that receives the title and the iframe url as a url parameter and updates its DOM to change the title and iframe src.
这篇关于更改Chrome扩展程序标签标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!