2016-01-06 97 views
9

我的頁面跳轉到時候我嵌入這個GDrive的iframe中,一旦你點擊了iframe頂部:頁面跳轉到頂部點擊iframe中時

<iframe height="400px" frameborder="0" width="600px" src="https://docs.google.com/document/d/1u9NFjTPBd-9mucQUPvkqLP84iV6uaEcJNF5vQdHmYh8/edit?usp=sharing&rm=embedded"></iframe> 

的jsfiddle:https://jsfiddle.net/0qpe53os/

問題:爲什麼它這樣做,我如何防止它這樣做?

我試圖preventDefault沒有任何運氣。提前感謝您的幫助。

+0

Mybe這可以幫助你http://stackoverflow.com/questions/26017978/iframe-causes-parent-elements-to-scroll-up-on-google-chrome-when-url-contains-fr – elTomato

+0

請看這裏:http://stackoverflow.com/questions/26017978/iframe-causes-parent-elements-to-scroll-up-on-google-chrome-when-url-contains-fr – leodido

回答

-2

您可以使用javascript檢查iframe是否爲活動元素,並在其處於活動狀態時跳轉回活動元素。

if(document.activeElement.tagName == 'IFRAME') { document.activeElement.scrollIntoView() }

的工作示例,請參見本Jsfiddle

1

我不確定這是否有用。順便說一下,您可以使用onload屬性向下滾動頁面: onload =「scroll(0,screen.height);」

<iframe height="400px" frameborder="0" width="600px" src="https://docs.google.com/document/d/1u9NFjTPBd-9mucQUPvkqLP84iV6uaEcJNF5vQdHmYh8/edit?usp=sharing&rm=embedded" onload="scroll(0,screen.height);"></iframe> 
0

從我的調查,它不是由iframe本身引起的。它的原因是嵌入式Google文檔執行的JavaScript。當google文檔的編輯區域收到焦點時,會發生這種情況。如果您訪問菜單區域,則不會發生任何事情,除非導致某些內容被添加到編輯區域。我試圖限制帶有sandbox屬性的iframe,並且這種行爲不會再發生,但是當然你不能使用google文檔。

對不起,沒有解決方案建議。