我正在尝试在 google chrome 扩展中添加自定义 coinbase 支付按钮。
我已经让它在 jsfiddle 中工作:http: //jsfiddle.net/hqhLV/
$(document).ready(function () {
code = "65a580d7449cc35869c9bd0d49cf77bd";
function get_button_html(code) {
var button_html = "<div class='coinbase-button' data-code='65a580d7449cc35869c9bd0d49cf77bd' data-button-style='none'></div>";
return button_html;
}
function loadButton(code) {
$('body').after("<a href='' class='my-custom-link'>Show Me The Modal!</a>", get_button_html(code));
};
loadButton(code);
$.getScript("https://coinbase.com/assets/button.js");
$('.my-custom-link').click(function () {
console.log('coinbase_show_modal');
$(document).trigger('coinbase_show_modal', '65a580d7449cc35869c9bd0d49cf77bd');
return false;
});
$(document).on('coinbase_payment_complete', function (event, code) {
console.log("Payment completed for button " + code);
window.location = "/confirmation.html";
});
});
但是,将代码复制为扩展中的内容脚本文件。知道可能是什么原因吗?