- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试为 chrome 做一个非常简单的扩展,但我坚持从弹出式 html 传递变量。
这是我目前的代码:
list :
{
"background": {
"scripts": [ "background.js" ]
},
"browser_action": {
"default_icon": "img/test.png",
"default_popup": "popup.html",
"default_title": "Auto Clicker"
},
"description": "Auto click",
"manifest_version": 2,
"name": "Auto Clicker",
"permissions": [ "activeTab" ],
"version": "0.0.1"
}
背景.js
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
switch (request.directive) {
case "popup-click-1":
// execute the content script
chrome.tabs.executeScript(null, { // defaults to the current tab
file: "myscript.js", // script to inject into page and run in sandbox
allFrames: true // This injects script into iframes in the page and doesn't work before 4.0.266.0.
});
sendResponse({}); // sending back empty response to sender
break;
}
}
);
我的脚本.js
function foo(){
document.getElementById('submit-button').click();
}
setInterval(function(){
foo()}, 20000)
foo();
弹出窗口
function clickHandler(e) {
chrome.extension.sendMessage({directive: "popup-click-1"}, function(response) {
this.close(); // close the popup when the background finishes processing request
});
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('submit').addEventListener('click', clickHandler);
})
弹出窗口
<html>
<head>
<title>test</title>
<script src="popup.js"></script>
</head>
<body>
test
<form>
<input id="1" type = "text">
</br>
</form>
<button id='submit'> etst </button>
</body>
</html>
到目前为止,当您单击每 20 秒运行一次的提交按钮时,我会运行 foo()。我想要实现的是在弹出的 html 中添加一个数字,然后在 myscript.js 中使用该数字来设置 setInterval 函数的时间。
下面是一个案例场景:
我打开页面,点击扩展按钮。有一个带有表单的弹出窗口。我投入了 30000,然后击中了 sumbit。这样,foo() 将每 30 秒运行一次。
最佳答案
不需要后台脚本。
在popup.js
中注入(inject)脚本并传递值:
function clickHandler(e) {
chrome.tabs.executeScript({
code: "var timeout=" + document.getElementById('1').value,
allFrames: true
}, function(result) {
chrome.tabs.executeScript({file: "myscript.js", allFrames: true}, function(result) {
});
});
}
myscript.js
将使用注入(inject)的 timeout
变量:
.............
setInterval(foo, timeout);
.............
关于javascript - Chrome 扩展 : pass variables from popup html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33479029/
希望你能帮助我。我阅读并再次阅读了 Magnific Popup 的文档,但我对 javascript 还不够好。 1- 我用这个链接打开一个弹出窗口: OPEN POPUP 和这个 javascri
我最近刚刚实现了“Magnific Popup”并且弹出窗口很好,但是当我单击一个输入框时,整个弹出窗口消失回到父页面。在插件网站上显示的示例中,整个对话框都是可单击的,直到您在该框外单击。 我希望它
我的弹出窗口正常工作,但有时用户会点击浏览器上的后退按钮关闭弹出窗口。 如何让浏览器后退按钮关闭已经打开的“magnific-popup”? 谢谢 最佳答案 经过一些挖掘发现 history.js 然
我制作了一个带有华丽弹出窗口的视频库。 但与图片库不同的是,视频库不显示计数器,例如1/3 在视频的右下角。为什么不?在图片库中,它运行良好。 视频库代码: $('.gallery_video').e
我正在使用 magnific popup 和 ajax 将内容加载到其中,并通过将查询字符串附加到 url 将值传递给 ajax 内容,除了在 IE7(可能还有 IE8)中工作正常。原因很可能是查询字
有没有办法绑定(bind)一个事件回调,以便为 Magnific Popup 的所有实例调用它?在我正在构建的网站上,当主浏览器滚动条消失时,几个元素具有固定位置和“跳转”。我想设置一个回调以在打开任
$.magnificPopup.open({ items: { src: $('#cabinet-msg') }, type:'inline', mid
在 jquery 对话框中我们可以做 $("#id").dialog('open|close') 打开关闭对话框。如何在 Magnific-popup 中做到这一点? 最佳答案 $.magnificP
我正在以这种方式制作新窗口: var WSHShell = WScript.CreateObject("WScript.Shell"); WSHShell.Popup("This is popup."
我打开一个带有 js 弹出窗口的 html 页面 Link to popup 现在我的弹出窗口中有一些链接,我想关闭我的链接的弹出窗口 onclick 并在旧窗口中打开链接。对于旧窗口,我指的是
无法在放大的弹出窗口中播放视频。 当我使用 class=iframe ,页面将重定向到 youtube 并播放视频。 但是当我使用 class=popup-youtube ,将显示弹出窗口,但我收到以
我有一个 Leaflet Popup 附加到一个标记,它给用户两个按钮来使用 jQuery 取消或移动到另一个页面。 这些按钮最初工作正常,除非您曾经准确地单击标记以使 Popup 消失,然后再次单击
我有 2 个 JQM 页面和 1 个它们共享的弹出窗口。我有一个事件处理程序绑定(bind)到两者的“pagecreate”,里面有这样的代码: $(document).on("pagecreate"
System.InvalidOperationException: You MUST call Rg.Plugins.Popup.Popup.Init(); prior to using it. 我已
测试 Magnific Popup 当前是否“打开”的最佳方法是什么? 检查某个 div 的存在是否会成为 future 的证明? 例如,如果我使用: if ($(".mfp-ready").leng
我的指令有问题。如果我从弹出 Controller 调用 $scope.popup.show = false 行,它就可以正常工作。如果我从子 contentDirective 调用 $scope.h
我在popup.js中有两个变量。我想把它们放在一起到一个 url ,无论如何就像 chrome.tabs.create({active: true, url: "https://"+savedApi
我有一些代码,它允许用户检查复选框并在提交时打开与新选项卡中的复选框关联的网址。如果两个复选框都被选中,则会打开两个选项卡。它的工作原理与预期一致,看起来像: document.getElementB
我有一个弹出窗口,其高度约为屏幕的 70%。我在这个弹出窗口中有 2 个 div, header-div 具有固定高度,例如20px 和一个 content-div,它应该使用剩余的可用高度。 目前我
我正在构建一个包含教程的 MMO。 当用户在教程中尝试离开教程或关闭选项卡/浏览器时,我需要显示一个自定义弹出窗口,其中包含有关用户退出教程的原因的选项。 我熟悉 onbeforeunload 事件,
我是一名优秀的程序员,十分优秀!