Chrome扩展程序:打开Jquery Ui对话框 [英] Chrome Extension: Opening Jquery Ui Dialog
问题描述
我对Chrome扩展开发非常陌生..我从谷歌的教程中获得了基本的想法,并从这个问题
这里是我迄今为止所做的
I'm very new to chrome extension development.. I got basic idea from google's tutorial and some help from this question here is what i have done so far
background.html
background.html
<html>
<head>
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null,
{file:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/ui-lightness/jquery-ui.css",
runAt:"document_start"},
function() { alert('Added css'); });
chrome.tabs.executeScript(null,
{file:"http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js",
runAt:"document_start"},
function () {
alert("loaded js");
chrome.tabs.executeScript(null,
{file:"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"},
function () {
alert("loaded js2");
chrome.tabs.executeScript(null, {file:"popup.js"}, function() {alert("did it pop up yet?");});
});
});
});
</script>
</head>
</html>
Manifest.json文件
Manifest.json file
{
"name": "demo",
"version": "2.0",
"description": "Jquery Dialog in Chrome",
"browser_action": {
"default_icon": "favicon.ico",
"default_title": "Dialog Box"
},
"background_page": "background.html",
"content_scripts": [
{
"matches": ["http://*/*","http://jquery.com/*"],
"js": ["jquery.js","popup.js"]
}
],
"permissions": [
"tabs","http://localhost/","http://*/*"
]
}
和我的ui对话框中的popup.js文件
And popup.js file where my ui dialog is
$(function() {
alert('in popup');
var NewDialog = $('<div id="MenuDialog"><p>This is your dialog content, which can be multiline and dynamic.</p></div>');
NewDialog.dialog({
modal: true,
title: "title",
show: 'clip',
hide: 'clip',
buttons: [
{text: "Submit", click: function() {doSomething()}},
{text: "Cancel", click: function() {$(this).dialog("close")}}
]
});
NewDialog.dialog("open");
});
我从background.html获取警报,但不是来自popup.js,jquery ui Dialog也没有出现。我试图调试它
I'm getting the alerts from the background.html but not from popup.js, jquery ui Dialog also not appears. I tried to debug it
我打开了gmail并单击了扩展控制台显示4个错误>
I opened gmail and clicked on extension console is showing 4 errors >
Error during tabs.executeScript: Cannot access contents of url "https://mail.google.com/mail/u/0/?shva=1#inbox". Extension manifest must request permission to access this host.
推荐答案
我认为错误信息非常清晰。您对 mail.google.com
on https
协议没有权限。
添加 https://mail.google.com/*
或更广泛的访问权限 *://*.google.com/*
给你的权限。
I think the error message is quite clear. You don't have permissions for mail.google.com
the on https
protocol.
Add https://mail.google.com/*
or for broader access *://*.google.com/*
to your permissions.
这篇关于Chrome扩展程序:打开Jquery Ui对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!