简体   繁体   English

在iframe中隐藏滚动条,并用页面上的滚动条替换

[英]Hide scrollbar from iframe and replace it with scrollbar on the page

I have iframe with vertical scrollbar. 我有垂直滚动条的iframe。 I need to remove it and have this scollbar at the the page. 我需要删除它,并在页面上保留此scollbar。 So, when I need to scroll the content of the iframe, I can use the page scrollbar. 因此,当我需要滚动iframe的内容时,可以使用页面滚动条。 I did hide the the vertical scrollbar from the iframe but now, I don't have it at all. 我确实从iframe中隐藏了垂直滚动条,但是现在,我根本没有它。 I use: 我用:

iframe::-webkit-scrollbar {  
    display: none;
  }  

And this works only with google chrome but it doesn't work with firefox and Internet Explorer. 而且这仅适用于Google Chrome,但不适用于Firefox和Internet Explorer。 I tried all the following: 我尝试了以下所有方法:

iframe::-moz-scrollbar {display:none;}
iframe::-o-scrollbar {display:none;}
iframe::-google-ms-scrollbar {display:none;}
iframe::-khtml-scrollbar {display:none;}

But they didn't work. 但是他们没有用。

So, I need your help to hide the scrollbar from iframe with all browsers. 因此,我需要您的帮助才能使用所有浏览器在iframe中隐藏滚动条。 And have the ability to scroll the iframe's content from the scrollbar of the page. 并能够从页面的滚动条滚动iframe的内容。 Thank you 谢谢

Depending on the version of IE, sometimes using iframe {overflow: hidden;} will hide the scrollbar. 根据IE的版本,有时使用iframe {overflow: hidden;}将隐藏滚动条。 But putting scrolling="no" in your iframe usually works on all browsers. 但通常在所有浏览器中都可以在iframe中使用scrolling="no"

You can add JavaScript to the page within the IFRAME to, on load and on resize, set the height of the IFRAME within the parent. 您可以将JavaScript添加到IFRAME中的页面,以在加载和调整大小时设置IFRAME在父级中的高度。 The page will need to exist within the same domain as the parent, although you may be able to overcome this with browser security settings. 该页面将需要与父页面位于同一域中,尽管您可以通过浏览器安全设置来克服此问题。

Within the page (example uses jQuery): 在页面内(示例使用jQuery):

if (window != window.parent)
    $(function() {
        var resize = function() { $(window.parent.document).find("IFRAME[name='" + window.name + "']").height($(document).height()); };
        $(window.parent).resize(resize);
        resize();
    });

You will need to give the iframe a name on the parent page: 您需要在父页面上为iframe命名:

<iframe name="anything" ...></iframe>

This seems to work just fine: 这似乎很好用:

Html 5/CSS HTML 5 / CSS

 .ifm { width: 1200px; height:800px; overflow-y: hidden; } 
 <iframe src="https://bing.com" class="ifm" scrolling="no" seamless="seamless"> </iframe> 

Based on this post. 根据这篇文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM