Chrome插件开发 popup.html Click事件

df_for_csdn 2016-10-07 03:15:38
请问html页面如何与js文件进行交互,可能我描述的不太准确,我目前想要实现这个chrome插件单击按钮在指定域进行ajax操作

function get_token() {
return location.href.substring(location.href.length, location.href.length - 10);
}
function get_csrf_token(token) {
var csrf_token = '';
$.ajax({
type: 'GET',
url: 'https://mp.weixin.qq.com/pay/index.php/dev_setting?token=' + token + '&lang=zh_CN',
async:false
}).success(function (data) {
var regCode = 'wx_csrf_token" value="(.*?)"';
csrf_token = data.match(regCode)[1];
});
return csrf_token;

}
function add_domain_publicPay(csrf_token, url) {
$.ajax({
type: 'POST',
url: 'https://mp.weixin.qq.com/pay/index.php/dev_setting/set_test_dir?g_ty=ajax',
data: 'wx_csrf_token=' + csrf_token + '&paydir='+url+'&dir=',
async: false
}).success(function (data) {
console.log(data);
});
}
function add_domain_callback(token,domain) {
$.ajax({
type: 'POST',
url: 'https://mp.weixin.qq.com/merchant/myservice?action=set_oauth_domain&f=json',
data: 'token='+token+'&lang=zh_CN&f=json&ajax=1&random=0.1394041796069092&domain='+domain,
async: false
}).success(function (data) {
console.log(data);
});
}


alert(document.cookie);

我现在遇到的问题是当我单击插件图标按钮时,此刻alert(document.cookie);生效,但popup页面没有被弹出显示,把这一句注释掉之后可以显示页面,但我注册了#btn-update的单击事件之后就不知道该怎么向js那边发起命令,总之就是html页要接收两个参数,然后单击按钮。

以下是我json文件跟html代码:

{
"manifest_version": 2,
"name": "WeCatApp",
"description": "weixin.qq.com",
"version": "1.0.0.0",
"icons": {
"32" : "icon.png"
},
"permissions": [
"tabs", "http://*/*","https://*/*"
],
"content_scripts": [
{"js":["jquery-1.7.1.js","wxpay.js"],"matches":["https://*.weixin.qq.com/*"]}
],
"browser_action": {
"default_title": "IT.HongWei",
"default_popup": "popup.html"
},
"manifest_version": 2
}


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
* {
margin:0px;
list-style:none;
font-family:微软雅黑;
}

div {
margin:0px auto;
width:300px;
}

ul {
padding-top: 15px;
padding-left: 0px;
}

ul li {
line-height:20px;
}

#btn-update {
margin-top: 10px;
/*margin-left: 112.375px;*/
margin-left: 60px;
width: 60%;
}

#li-btn-update {
height:50px;
}

span {
margin-left: 60px;
}

.form-control-user {
display: block;
width: 60%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
color: #555;
background-color: #fff;
background-image: none;
border: 1px solid #ccc;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
-webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s;
-o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
margin-left: 60px;
}
</style>
<link href="bootstrap.min.css" rel="stylesheet">
<script src="wxpay.js"></script>
<script src="jquery-1.7.1.js"></script>
<script>
//<meta http-equiv="refresh" content="20">
function btnClickEvent() {

}
</script>


</head>
<body>
<div>
<ul>
<li><h6><span class="label label-Default">支付域名</span></h6></li>
<li><input id="txt-payUrl" type="text" class="form-control-user" placeholder="支付授权目录" required autofocus value="onelaughcs.cn" /></li>
<li><h6><span class="label label-Default">回调域名</span></h6></li>
<li><input id="txt-callUrl" type="text" class="form-control-user" placeholder="OAuth2.0授权回调" value="onelaughcs.cn" /></li>
<li id="li-btn-update"><input type="button" id="btn-update" class="btn btn-primary " value="确定更新" onclick="btnClickEvent()"/></li>
</ul>
</div>


</body>
</html>


一夜未眠始终无果,恳求帮助
...全文
1620 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
或许可能 2016-10-19
  • 打赏
  • 举报
回复 1
HTML 中不能有 <script> //<meta http-equiv="refresh" content="20"> function btnClickEvent() { } </script> 会被替换掉,所有的JS只能写在外部文件。这在谷歌API文档上是一个很显眼的提示哦
一个为chrome设计的rikaichan港口。翻译日语:在单词上盘旋。 *Version History Below* This is a port of rikaichan to chrome. For arbitrary reasons, I've called it rikaikun. Activate the extension by clicking on the 理 in the top right. Some people have reported that loading might take up to 10 seconds on OSX. When the introductory pop up appears, rikaikun is ready for action. When it's activated, when you hover over Japanese words they'll be translated in a pop up. If you hit shift/enter, you'll see some information about the first Kanji. It's not as done as I wanted, but please file issues at the link provided if you have any problems or feature requests. If you click on the "Details" tab you can find a link to the support page where you can file bugs and feature requests. v0.10.0 Features Scrolling to see >7 dictionary entries by bazzinotti. Add Heisig keywords to Kanji dictionary by Vwing. Add Heisig 6th edition by Vwing. Add Text To Speech support (enable in settings) by MayamaTakeshi. Options appear in pop up instead of new page by darren-lester. Settings use cloud sync and persist across all computers by Deshaun Crawford. Bug Fixes CTRL-C works properly to copy just the word instead of copying the full definition by darren-lester. Google Docs mostly works again after they updated their rendering logic. v0.9.1 Fixes textarea bug. v0.9.0 Faster dictionary loading. Popup delay added and popups can be configured to only show up when a key is pressed. Popup location default can be configured via options. Various bug fixes. v0.8.91 jQuery was removed and a bug common on angular pages. v0.8.9 Names dictionary is added. It's quite large but shouldn't be a problem for modern computers. v0.8.7 Fixed bug where rikaikun would stop working and need to be turned off and on again. v0.8.6 Added readings only mode that can be turned on in the options. It allows you to not see English definitions if you don't want to. v0.8.5 Fixed various bugs. Added text fields and button capability. By default

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧