Javascript AdobeEdge HTML5本地连接
我正在尝试用adobeEdge创建两个横幅,并用iframes在第三个文件中导入它们。所以结构应该是这样的: banner1.html banner2.html index.html(其中banner1和banner2将通过iframe嵌入) 这两个横幅将设置动画,但是文件大小、每个横幅的加载时间可能不同,因此不会同时加载 问题是,我需要两个iFrame在完全相同的时间开始播放(在称为本地连接的flash中),因此,我的想法是检查两个iFrame何时加载,以及它们是否都向另一个发送“完成”消息,我将播放它们 我写了一个代码,这实际上是工作,但仍然有一个横幅总是有一个延迟。这是我的密码: 横幅1Javascript AdobeEdge HTML5本地连接,javascript,html,iframe,adobe-edge,Javascript,Html,Iframe,Adobe Edge,我正在尝试用adobeEdge创建两个横幅,并用iframes在第三个文件中导入它们。所以结构应该是这样的: banner1.html banner2.html index.html(其中banner1和banner2将通过iframe嵌入) 这两个横幅将设置动画,但是文件大小、每个横幅的加载时间可能不同,因此不会同时加载 问题是,我需要两个iFrame在完全相同的时间开始播放(在称为本地连接的flash中),因此,我的想法是检查两个iFrame何时加载,以及它们是否都向另一个发送“完成”消息,
<script type="text/javascript">
var fr = window.parent.frames["frame2"];
var frwin = fr.contentWindow;
var otherLoaded = false;
var selfLoaded = false;
var process = setInterval(function(){load();},10);
window.addEventListener("message", receiveMessage, false);
function setLoaded(){
selfLoaded = true;
frwin.postMessage("Done", "DOMAIN");
}
function load(){
if(otherLoaded === true && selfLoaded === true){
clearInterval(process);
AdobeEdge.bootstrapCallback(function(compId) {
AdobeEdge.getComposition(compId).getStage().play();
});
}else if(selfLoaded === true && otherLoaded !== true){
frwin.postMessage("resend", "http://izorgor.com");
}
}
function receiveMessage(event) {
if (event.origin !== "DOMAIN")
return;
if(event.data === 'Done'){
otherLoaded = true;
console.log("Done");
}
if(event.data === 'resend'){
fr = window.parent.frames["frame2"];
frwin = fr.contentWindow;
frwin.postMessage("Done", "DOMAIN");
console.log("resend");
}
}
</script>
var fr=window.parent.frames[“frames2”];
var frwin=fr.contentWindow;
var-otherload=false;
var自加载=假;
var进程=setInterval(函数(){load();},10);
window.addEventListener(“消息”,receiveMessage,false);
函数setLoaded(){
自加载=真;
frwin.postMessage(“完成”、“域”);
}
函数加载(){
if(otherLoaded==true&&selfLoaded==true){
clearInterval(过程);
AdobeEdge.bootstrapCallback(函数(compId){
getComposition(compId.getStage().play();
});
}else if(selfLoaded==true&&otherLoaded!==true){
frwin.postMessage(“重新发送”http://izorgor.com");
}
}
函数接收消息(事件){
如果(event.origin!=“域”)
返回;
如果(event.data===“完成”){
otherLoaded=true;
控制台日志(“完成”);
}
如果(event.data===‘重新发送’){
fr=window.parent.frames[“frames2”];
frwin=fr.contentWindow;
frwin.postMessage(“完成”、“域”);
控制台日志(“重新发送”);
}
}
横幅2
<script type="text/javascript">
var fr = window.parent.frames["frame1"];
var frwin = fr.contentWindow;
var otherLoaded = false;
var selfLoaded = false;
var process = setInterval(function(){load();},10);
window.addEventListener("message", receiveMessage, false);
function setLoaded(){
selfLoaded = true;
frwin.postMessage("Done", "DOMAIN");
}
function load(){
if(otherLoaded === true && selfLoaded === true){
clearInterval(process);
AdobeEdge.bootstrapCallback(function(compId) {
AdobeEdge.getComposition(compId).getStage().play();
});
}else if(selfLoaded === true && otherLoaded !== true){
frwin.postMessage("resend", "http://izorgor.com");
}
}
function receiveMessage(event) {
if (event.origin !== "DOMAIN")
return;
if(event.data === 'Done'){
otherLoaded = true;
console.log("Done");
}
if(event.data === 'resend'){
fr = window.parent.frames["frame1"];
frwin = fr.contentWindow;
frwin.postMessage("Done", "DOMAIN");
console.log("resend");
}
}
</script>
var fr=window.parent.frames[“frame1”];
var frwin=fr.contentWindow;
var-otherload=false;
var自加载=假;
var进程=setInterval(函数(){load();},10);
window.addEventListener(“消息”,receiveMessage,false);
函数setLoaded(){
自加载=真;
frwin.postMessage(“完成”、“域”);
}
函数加载(){
if(otherLoaded==true&&selfLoaded==true){
clearInterval(过程);
AdobeEdge.bootstrapCallback(函数(compId){
getComposition(compId.getStage().play();
});
}else if(selfLoaded==true&&otherLoaded!==true){
frwin.postMessage(“重新发送”http://izorgor.com");
}
}
函数接收消息(事件){
如果(event.origin!=“域”)
返回;
如果(event.data===“完成”){
otherLoaded=true;
控制台日志(“完成”);
}
如果(event.data===‘重新发送’){
fr=window.parent.frames[“frame1”];
frwin=fr.contentWindow;
frwin.postMessage(“完成”、“域”);
控制台日志(“重新发送”);
}
}
index.html
<iframe width="900" height="200" id="frame1" src="banner1.html" frameborder="0" scrolling="no"></iframe>
谢谢我想你应该联系你的广告服务器,问问他们是用一个标签还是两个标签来提供广告 您可以将库用作
(类似于Flash本地连接)您可以使用我开发的JavaScript库在窗口中的所有iFrame之间进行通信。 得到或。它使用nativ DOM将iFrame彼此连接起来 示例用法: 将第一个LocalConnection脚本包含到所有横幅中。在这个示例代码中,我们假设有两个横幅需要相互通信。但它也适用于任何数量的横幅 在第一条横幅中:
<script>
LC.key = 'uniqueConnectionString';
LC.name = 'right'; // desc: my name is right and
LC.frames = 'left'; // I want to connect to the banner called left
LC.onConnect = function () {
console.log('Do this as soon as connection established!');
/*
From this point window of left and top will be available as
LC.left and LC.top
for example :
*/
LC.left.document.getElementsByTagName('body')[0].style.backgroundColor = 'pink';
};
</script>
LC.key='uniqueConnectionString';
LC.name='右';//描述:我的名字是正确的
LC.frames='左';//我想连接到名为left的横幅
LC.onConnect=函数(){
log('建立连接后立即执行此操作!');
/*
从这一点来看,左侧和顶部的窗口将作为
左,右上
例如:
*/
LC.left.document.getElementsByTagName('body')[0].style.backgroundColor='pink';
};
在第二条横幅上放置相同的代码,但更改名称和帧值,如下所示:
<script>
LC.key = 'uniqueConnectionString';
LC.name = 'left'; // desc: my name is left and
LC.frames = 'right'; // I want to connect to the banner called right
LC.onConnect = function () {
console.log('Do this as soon as connection established!');
/*
From this point window of left and top will be available as
LC.left and LC.top
for example :
*/
LC.left.document.getElementsByTagName('body')[0].style.backgroundColor = 'pink';
};
LC.connect();
</script>
LC.key='uniqueConnectionString';
LC.name='左';//我的名字是左和右
LC.frames='右';//我想连接到名为right的横幅
LC.onConnect=函数(){
log('建立连接后立即执行此操作!');
/*
从这一点来看,左侧和顶部的窗口将作为
左,右上
例如:
*/
LC.left.document.getElementsByTagName('body')[0].style.backgroundColor='pink';
};
LC.connect();
AdServer将墙纸横幅作为两个不同的iFrame提供。我的第一个想法是在这两者之间交换postMessage(我上面的脚本)。但由于某种原因,当我在这两种格式之间转换某个对象时,我发现hey并不是在完全相同的时间开始的。感谢这个脚本,我将尝试一下堆栈溢出!一个链接到一个潜在的解决方案总是受欢迎的,但请你这样做,你的同事用户将有一些想法,它是什么,为什么会在那里。始终引用重要链接中最相关的部分,以防无法访问目标站点或永久脱机。考虑到仅仅是一个指向外部站点的链接是一个可能的原因。