在 Chrome 扩展程序中将鼠标悬停在广告上使用时遇到问题
Trouble using mouseover on ad in Chrome extension
作为Chrome扩展程序的一部分,我正在尝试检测您将鼠标悬停在广告上的时间。 现在,我只在《纽约时报》的头版进行测试。 内容脚本的问题区域如下:
$(document).ready(function (){
setTimeout(function() {
console.log("starting...");
console.log(document.querySelectorAll("iframe"));
var frames = $("iframe").contents().find(".ad-frame.frame-for-homepage");
console.log(frames);
frames.on("mouseover", function(event){
console.log("on ad");
});
}, 10000);
});
setTimeout 函数是特定于在页面上获取正确 iframe 的技巧。 控制台.log显示它会挑选出包含广告的正确 iframe,但鼠标悬停事件不会触发。 实际上,它似乎不会运行任何超过querySelectorAll行的内容,因为没有出现进一步的console.logs。
如果我将鼠标悬停移到 setTimeout 函数之外,它会在鼠标悬停页面上的任何元素时触发。
我对此有点困难,因此非常感谢任何帮助。 谢谢
选择器不正确,您可以简化代码以使其工作,因为广告iframe
具有.ad-frame.frame-for-homepage
类。这工作正常:
$(document).ready(function (){
setTimeout(function() {
console.log("starting...");
console.log(document.querySelectorAll("iframe"));
var frames = $("iframe.ad-frame.frame-for-homepage");
console.log(frames);
frames.on("mouseover", function(event){
console.log("on ad");
});
}, 10000);
});
编辑:将其作为Chrome扩展程序进行了测试,并且工作正常,将鼠标悬停在广告上时,控制台会记录"广告",除了顶部的flash(我检查了一下,iframe有height:0
)
相关文章:
- 将PHP变量传递给jQuery时遇到问题
- 我的jQuery插件参数没有正确启动,遇到了问题
- 在AJAX回调和呈现PIXIJS之间处理程序流时遇到了问题
- 将jQuery转换为用户脚本的普通Javascript时遇到问题
- 将子文档推送到父数组时遇到问题
- JQuery FullCalendar在从ajax成功调用rerenderEvents时遇到问题
- 在将javascript附加到我的html中时遇到问题
- 遇到400错误请求(Angular+WebAPI)的问题
- 为什么我在以编程方式打开窗口时遇到问题
- 在将缩略图链接到模态时遇到问题
- 在我的网站上创建一个在1-10之间不断变化的数字时遇到了问题.Javascript
- 使用 ng 模型获取数据时遇到问题
- 是否有其他人在设计Twitter Typeahead时遇到问题'的搜索栏
- 使用jquery进行整数比较时遇到问题
- 使用PhantomJS下载动态web内容时遇到问题
- 设置RequireJS时遇到问题
- 让Javascript在SharePoint 2010上运行时遇到问题
- I'我在react.js中编写for循环时遇到问题
- 为什么我在对话框中遇到Ajax请求问题
- 通过jQuery获取上传的文件名时遇到问题