2016-05-30 78 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