简体   繁体   English

在iframe页面中添加/更改css

[英]adding/ changing css in Iframe page

I have been tasked to use this approach a SharePoint 2013 site, so here goes. 我的任务是将此方法用于SharePoint 2013网站,所以这里是。

Background: - I have a page in a SharePoint 2013 site, which has a "content editor" webpart displaying a page from within the same domain/site collection. 背景: - 我在SharePoint 2013网站中有一个页面,其中有一个“内容编辑器”webpart,显示同一域/网站集中的页面。 The below code (which is not mine) I have placed in the content editor and it displays the page all fine. 下面的代码(不是我的)我放在内容编辑器中,它显示页面都很好。

Issue - My requirement is to "remove the globalnav" from the page within the content editor which I presume is using an Iframe. 问题 - 我的要求是在内容编辑器中从页面中“删除globalnav”,我认为它正在使用Iframe。 Now I can use the F12 dev tools with IE11 and find the CSS class which is the follow - ms-dialog #globalNavBox and set the display to "none" this is exactly how I want it to look. 现在我可以使用IE11的F12开发工具找到CSS类,这是后面的ms对话框#globalNavBox ,并将显示设置为“none”,这正是我想要的样子。

The only thing I do not know how to achieve here is how to make this happen via using some sort of code on the page displaying the embedded page.?? 我唯一不知道如何实现的是如何通过在显示嵌入页面的页面上使用某种代码来实现这一点。

this is the code I am using in the content editor to display my page I want to modify. 这是我在内容编辑器中使用的代码,用于显示我想要修改的页面。

#mydiv{

width:1280px; height:1000px;
 overflow:hidden;
 ;
}

#myframe{
 ;
 top:-190px;
 left:-100px;
 width:1080px;
 height:1000px;

}
</style>
<div id="mydiv">
<iframe id="myframe" src="/gen/genInduction/Lists...blah scrolling="no"></iframe>&#160;</div>

now I have no idea how to add in the code (if I can) to remove the css .ms-dialog #globalNavBox {display: none;} so that when the page is displayed the globalnav is removed. 现在我不知道如何添加代码(如果可以的话)删除css .ms-dialog #globalNavBox {display:none;}以便在显示页面时删除globalnav。

I hope this makes sense as this is the first time I have used this site to ask a question. 我希望这是有道理的,因为这是我第一次使用这个网站提问。 I have also searched endlessly before I asked this question and have tried various things to make this work but I just cant/understand how to make this happen. 在我提出这个问题并尝试了各种各样的事情来完成这项工作之前,我也无休止地进行了搜索,但我不能理解如何实现这一目标。

Place the following in the page after the iframe 将以下内容放在iframe 之后的页面中

<script>
document.getElementById("myframe").contentDocument.getElementById("globalNavBox").style.display="none";
</script>

I believe you'll still be able to access the iframe's content since they both belong to the same domain, unless the iframe is sandboxed (which the example clearly shows it isn't). 我相信您仍然可以访问iframe的内容,因为它们都属于同一个域,除非iframe是沙盒(示例清楚地表明它不是)。 Adding to JBiserkov's slick streamlined answer, this will cover some concerns with loading of the iframe. 添加到JBiserkov的简洁流畅的答案,这将涵盖加载iframe的一些问题。 Under many circumstances, an iframe might be a little late to the party, so you should be prepared for that. 在很多情况下,一个iframe可能会晚一点,所以你应该为此做好准备。 The following links helped me understand iframes: 以下链接帮助我了解iframe:

Iframes, Onload, and Document.domain iframe,Onload和Document.domain

Iframe Tutorials iframe教程

-Reference to the iframe - 参考iframe

var iFrame = document.getElementById('myframe'),

-Reference to the iframe's document object - 参考iframe的文档对象

-This shorthand conditional expression is the key to accessing any content inside the iframed page. - 这种速记条件表达式是访问iframed页面内任何内容的关键。

iDoc = iFrame.contentDocument ? iFrame.contentDocument : iFrame.contentWindow.document,

-Reference to the target element #globalNavBox - 对目标元素#globalNavBox的引用

gNav = iDoc.getElementById('globalNavBox');

-When the iframe is loaded, grab globalNavBox's style to "display" and set to "none" - 加载iframe时,将globalNavBox的样式设为“display”并设置为“none”

iframe.onload = function () {
        gNav.style.display = 'none';
};

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

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