簡體   English   中英

在Chrome擴展程序中的廣告上使用鼠標懸停時遇到問題

[英]Trouble using mouseover on ad in Chrome extension

作為Chrome擴展程序的一部分,我試圖檢測您何時將鼠標懸停在廣告上。 現在,我僅在NYT頭版上進行測試。 內容腳本的問題區域如下:

$(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的一種技巧。 console.log顯示,它會選擇包含廣告的正確iframe,但是不會觸發mouseover事件。 實際上看起來它不會在querySelectorAll行之后運行任何內容,因為沒有進一步的console.logs出現。

如果將鼠標懸停在setTimeout函數之外,則在頁面上任何元素的鼠標懸停時都會觸發。

我已經為此碰到了牆,所以可以提供任何幫助。 謝謝

選擇器不正確,您可以簡化代碼以使其工作,因為ad 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擴展程序進行了測試,並且工作正常,將鼠標懸停在廣告上時,控制台會在廣告上記錄“ on ad”,但頂部上方是Flash(我檢查過,iframe的height:0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM