我正在创建一个 Google Chrome 扩展程序,它根据提供的选项进行一些基本搜索。
这是到目前为止的样子

问题是侧面有很多不好看的空白区域,特别是因为这是一个弹出窗口并叠加在当前页面上。
如何确保弹出窗口使用所需的最小空间量?
我想用动态创建的选项创建一个选项页面。
我正在使用我的内容脚本从网页源中提取一些数据,并且我希望该数据显示在选项页面中。我怎样才能将该数据发送到我的选项页面?
我在内容脚本中使用了localStorage,但在选项页面中无法访问。
如果在选项页面中创建,则可以在后台页面和内容脚本中访问localStorage。但是,如果我在内容脚本中创建它,则无法在选项页面中访问它。
我怎样才能做到这一点?
manifest.json 中定义了一个内容脚本。内容脚本正在执行一项简单的任务。它将iframe添加到页面中并尝试在其中打开本地 HTML文件。
问题是:
ifrm.setAttribute("src", "http://www.xyz.com/"); //working correctly.
Run Code Online (Sandbox Code Playgroud)
但
ifrm.setAttribute("src", chrome.extension.getURL("view/abc.html")); //Not working
Run Code Online (Sandbox Code Playgroud)
iframe 未打开本地 HTML 文件。
任何建议...
html javascript iframe google-chrome-extension content-script
这就是我想要做的。
首先,这是在 Chrome 扩展程序中。
在 popup.js 文件中,它运行在 popup.html 上(这段代码是设置值,当我选择一个选择选项时):
function mySelectValue() {
// Add an event listener for the value
document.getElementById('mySelectValue').addEventListener('change', function() {
// Get the value of the name field.
var mySelectValue = document.getElementById('mySelectValue').value;
// Save the name in localStorage.
localStorage.setItem('mySelectValue', mySelectValue);
});
}
Run Code Online (Sandbox Code Playgroud)
现在之后我有代码来检索现在应该存储在 localstorage 中的值:
function getAndDisplayTheValue() {
myValue = localStorage.getItem('mySelectValue');
document.write(myValue);
}
Run Code Online (Sandbox Code Playgroud)
好的,这就是 javascript 文件。现在这里是 popup.html 文件:
<select id="mySelectValue">
<option name="" value="">choose a value</option>
<option value="first" name="first">first value</option>
<option value="second" name="second">second value</option>
<option value="third" name="third">third value</option> …Run Code Online (Sandbox Code Playgroud) chrome.runtime.sendMessage();
Run Code Online (Sandbox Code Playgroud)
我想从我的 contentscript.js 向 popup.js 传递多个(具体为 2 个)消息。
我不需要这个函数的其他参数,我只需要message参数。
在我的 contentscript.js 我有这个:
chrome.runtime.sendMessage(message1);
chrome.runtime.sendMessage(message2);
Run Code Online (Sandbox Code Playgroud)
这是我的 popup.js:
chrome.runtime.onMessage.addListener(function(messsage1){
//code for handling the message
});
chrome.runtime.onMessage.addListener(function(messsage2){
//code for handling the message
});
Run Code Online (Sandbox Code Playgroud)
我想将这两个函数组合成一个函数并处理如下消息:
chrome.runtime.onMessage.addListener(function(){
// how to write the parameter for this function, I can't use ',' right?
// code for handling the message1, message2
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
javascript google-chrome message-passing google-chrome-extension
我想提取 chrome 扩展的当前浏览器的 uiLocale 以向服务器中的一个页面发出 ajax 请求。
我现在有 @@ui_locale 但我不能在例如 alert();
有任何想法吗?
谢谢。
在为我的 Chrome 扩展程序使用默认弹出窗口时,我无法更改扩展程序状态的图标。如果我禁用 popup.html 状态更改图标正在工作。我使用了一种切换方法来更改图标,该方法在不使用 popup.html 的情况下运行良好。这怎么可能?有人可以帮我吗?
提前致谢!
如果隐身模式已激活,我可以使用 chrome 扩展程序进行检查,或者我可以使用扩展程序中的按钮启动隐身模式吗?
当用户按下按钮时,我想自动隐藏我的页面操作的弹出窗口。正如我在 Chromium 论坛上读到的,这在 2011 年是不可能的——有人知道这是否可能,如果是,如何实现?
问候弗洛里安
更新:好的,这真的很简单。就像window.close()弹出窗口实际上是嵌入页面的窗口一样。有人发表了一条评论,将我带到了这个解决方案 - 但出于某种原因,他删除了他的评论......
在我的代码中,我希望能够创建通知,但以下代码不起作用。我似乎无法在任何地方找到教程,而且 API 对我来说毫无意义。这是我的代码,感谢所有帮助。谢谢!
function notify(string) {
chrome.notifications.create(string)
}
notify("Testing")
Run Code Online (Sandbox Code Playgroud)
在我的清单中:
"permissions": [ "unlimitedStorage", "tabs", "notifications"]
Run Code Online (Sandbox Code Playgroud)