Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使iframe覆盖基本页的html?_Javascript_Jquery_Html_Iframe - Fatal编程技术网

Javascript 如何使iframe覆盖基本页的html?

Javascript 如何使iframe覆盖基本页的html?,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,我现在这样做是为了注入一个iframe: var iFrame = document.createElement ("iframe"); iFrame.src = chrome.extension.getURL ("chrome.html"); iFrame.setAttribute("scrolling", "no"); iFrame.setAttribute("frameborder", "0"); iFrame.setAttribute("style", "border:none; w

我现在这样做是为了注入一个iframe:

var iFrame  = document.createElement ("iframe");
iFrame.src  = chrome.extension.getURL ("chrome.html");
iFrame.setAttribute("scrolling", "no");
iFrame.setAttribute("frameborder", "0");
iFrame.setAttribute("style", "border:none; width:100%; height:20%");
document.body.insertBefore (iFrame, document.body.firstChild);
虽然它工作得很好,但它将iframe注入到web页面的顶部。因此,如果已向下滚动,则必须向上滚动才能查看iframe。我想知道如何在页面顶部添加一个iframe,它就像一个下拉菜单(下拉到页面顶部),在滚动后消失

添加以下内容:

function checkScroll()
{
    //remove the iframe
    //iFrame.parentNode.removeChild(iFrame);

    //or remove after 2 secs
    setTimeout(function(){ iFrame.parentNode.removeChild(iFrame); }, 2000);

    //off the scroll listener
    document.removeEventListener('scroll', checkScroll); 
}
document.addEventListener('scroll', checkScroll); 

您创建了一个位于页面顶部的空容器(z索引,绝对定位),并将ifram添加到其中,而不是身体的第一个子项。您可以通过JavaScript在Scroll上隐藏容器。

您的意思是滚动后不消失?不完全是。我的意思是在滚动后消失,或者当你开始滚动时消失。啊!我明白你的意思。是的,当你们开始滚动时不会消失,但会在3到4秒钟的下拉列表中消失。谢谢。但是,我如何在绝对顶部位置添加iFrame呢?我将其设置为固定位置(请参见css),以便在css完全扰乱iFrame在各种网站上的位置时可以看到。我知道,您需要针对刚刚创建的特定iFrame,对吗?添加iFrame.style.position=“固定”;看这里