嘿,我有点迟了但我的代码有问题..
function Orientation()
{
if ( (window.orientation == 0) || (window.orientation == 180) )//portrait
{
Paysage.style.visibility = "hidden";
Portrait.style.visibility = "visible";
mraid.removeEventListener("stateChange", mraidIsReady);
mraid.removeEventListener("orientationchange", mraidIsReady);
mraid.addEventListener("orientationchange", Orientation);
mraid.addEventListener("stateChange", Orientation);
//var video = document.getElementById("video");
//video.pause();
}
if ( (window.orientation == 90) || (window.orientation == -90) )//paysages
{
Portrait.style.visibility = "hidden";
Paysage.style.visibility = "visible";
mraid.removeEventListener("stateChange", mraidIsReady);
mraid.removeEventListener("orientationchange", mraidIsReady);
mraid.addEventListener("orientationchange", Orientation);
mraid.addEventListener("stateChange", Orientation);
//var video = document.getElementById("video");
//video.play();
//overlayObj.style.visibility = "";
//var video = document.getElementById("video");
//video.play();
}
}
function doReadyCheck()
{
if (mraid.getState() == 'loading')
{
mraid.addEventListener("orientationchange", Orientation);
mraid.addEventListener("stateChange", Orientation);
}
else
{
mraid.addEventListener("orientationchange", Orientation);
mraid.addEventListener("stateChange", Orientation);
}
}
doReadyCheck();
</script>
我的EvetListener在加载时总是工作但在它之后它不再工作了......
顺便说一句,我有一个代码在IOS上工作以阻止横向的方向,但它不适用于Android为什么?
谢谢! :)
答案 0 :(得分:0)
我注意到您的代码存在一些问题
<script src="mraid.js"></script>
,很可能是因为您没有在脚本代码中粘贴整个代码。mraid.addEventListener("orientationchange", Orientation);
然后
移除你应该打电话
mraid.removeEventListener("orientationchange", Orientation);
而非mraid.removeEventListener("orientationchange", mraidIsReady);
第五,如果您的广告SDK不支持该更改事件,那么并非所有人都会抱怨SDK的支持方向更改
window.addEventListener(&#39; orientationchange&#39;,取向);
这是代码
<script src="mraid.js"></script>
function Orientation()
{
if ( (window.orientation == 0) || (window.orientation == 180) )//portrait
{
Paysage.style.visibility = "hidden";
Portrait.style.visibility = "visible";
}
if ( (window.orientation == 90) || (window.orientation == -90) )//paysages
{
Portrait.style.visibility = "hidden";
Paysage.style.visibility = "visible";
}
}
function doReadyCheck()
{
if (mraid.getState() == 'loading')
{
//Mraid is still loading so listen to ready state change
mraid.addEventListener("ready", mraidIsReady);
}
else
{
//Mraid is already ready so do your mraid related stuff here
//orientationchange event will only be added in case your SDK supports orientationchange otherwise add
//window.addEventListener("orientationchange", Orientation);
mraid.addEventListener("orientationchange", Orientation);
//This is not needed,why do you need to listen to stateChange as well, but its upto you if you want to do that
//mraid.addEventListener("stateChange", Orientation);
}
}
/**
* Mraid is ready, so add your mraid related code here
*/
function mraidIsReady(){
//Remove the ready listener
mraid.removeEventListener("ready", mraidIsReady);
//Now add mraid related listeners
//orientationchange even will only be added in case your SDK supports orientationchange otherwise add //window.addEventListener("orientationchange", Orientation);
mraid.addEventListener("orientationchange", Orientation);
//I don't know if you really need to do that this is un-necessary, so every stateChange will trigger orientation check
//mraid.addEventListener("stateChange", Orientation);
}
doReadyCheck();