2016-05-30 74 views
0

我试图通过跨域调整Sharepoint环境内的iframe大小。我试着在网络上并没有什么发现一堆解决方案的工作,除了贝克Humadi的附近约postMessage的最终解决方案:带Sharepoint的postMessage iframe调整大小无法正常工作

https://stackoverflow.com/a/15558627/2171556

我添加了一个脚本编辑器到SharePoint页面下面的(我的iframe网址当然指点我的孩子页):

<script> 
// Create IE + others compatible event handler 
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; 
var eventer = window[eventMethod]; 
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; 

// Listen to message from child window 
eventer(messageEvent,function(e) { 
    document.getElementById('frame').height = e.data + 'px'; 
},false); 
</script> 

<iframe id="frame" src="childpage" scrolling="no"></iframe> 

在我包括以下(RestSection被一些其他方式填充,所以请忽略这个帖子的内容)的子页面:

<script type="text/javascript"> 
window.onload = function() 
{ 
    var actual_height = document.getElementById('RestSection').scrollHeight; 
    parent.postMessage(actual_height,"childpage"); 
    //* allows this to post to any parent iframe regardless of domain 
} 
</script> 

<div id="RestSection"> 
    //List of things 
</div> 

当我编辑Sharepoint中的代码片段时,它实际上是按照它应该调整页面的大小。当我检查在它停止工作,我已经注意到了高度设置很奇怪 - 也许有些postMessage的对象?:

<iframe id="frame" src="childpage" scrolling="no" height="{"command":"RequestSuccess","requestIndex":1,"result":null}px"></iframe> 

我不明白为什么它的工作原理,当我编辑的页面在Sharepoint但突然当我检查它时不会。有没有人见过这种行为,或者可以在某种程度上启发我?

回答

0

也许你应该在这里寻求帮助的是SharePoint子网https://sharepoint.stackexchange.com/。在编辑模式下工作但不能在视图中运行的脚本是一种常见的失败。

+0

好的,谢谢,我会在那里重定向我的问题。 – Ghost