Commit f1e15910 authored by asdf's avatar asdf

iframe添加监听

parent a570544e
...@@ -122,14 +122,16 @@ cc.Class({ ...@@ -122,14 +122,16 @@ cc.Class({
this.preloadItem() this.preloadItem()
} }
}) })
var testiframe = document.getElementById("previewFrame");
window.addEventListener('message',(e)=>{ if (testiframe) {
let msgData = e.data; testiframe.contentWindow.addEventListener('message', (e) => {
console.log(msgData.action) let msgData = e.data;
if(msgData.action==="course-ready"){ console.log(msgData.action)
this.stopBgm(); if (msgData.action === "course-ready") {
} this.stopBgm();
}); }
});
}
}, },
getData(cb) { getData(cb) {
...@@ -204,8 +206,8 @@ cc.Class({ ...@@ -204,8 +206,8 @@ cc.Class({
this.bgAudioId = cc.audioEngine.play(clip, true, 1); this.bgAudioId = cc.audioEngine.play(clip, true, 1);
}); });
}, },
stopBgm(){ stopBgm() {
if(this.bgAudioId){ if (this.bgAudioId) {
cc.audioEngine.stop(this.bgAudioId); cc.audioEngine.stop(this.bgAudioId);
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment