如何更改iframe的方向 [英] How to change the iframe's orientation
问题描述
就我而言,我已经将由另一个组织(是的,我被授权这样做)开发的html游戏嵌入到一个网站中。页面和HTML游戏文件都位于同一个域中。
In my case, I have embedded a html game that developed by another organization (yes, I was authorized to do so) into a website. Both the page and the HTML game files sits in the same domain.
该游戏是为了支持iPad而开发的,但仅限于横向游戏。但是在iframe中,即使我已经在iPad设备中显示,也会始终显示请使用横向的消息。所以,我认为iframe的方向始终是纵向。
The game was developed to support iPad but only in landscape orientation. However in a iframe, it always display the message that "Please use the landscape orientation" even if I have already done so in the iPad device. So, I assume the iframe's orientation is always portrait.
是否可以手动设置iframe的方向?在我的情况下,我会将其设置为横向。
Is it possible that set a iframe's orientation manually? In my situation, I would set it as landscape orientation.
提前致谢。
推荐答案
此行为是设计使然。
您必须告知iframe中方向更改的页面。所以在你的主页中:
You have to tell the page in the iframe of the orientation change. So in your host page:
window.addEventListener("orientationchange", function() {
var iframe = document.getElementById("youriframe").contentWindow;
iframe.postMessage({
orientation: window.orientation
}, 'http://the.domain.of.the.iframe.com');
}, false);
在托管页面中:
window.addEventListener("message", function( e ) {
window.orientation = e.data.orientation;
}, false);
这篇关于如何更改iframe的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!