下記のコードにおいてif構文内において「document.getElementById("iframe-contents").style.height = e.data + "px";」を実行させたいのですが、「 console.log("aaa")」を記述を入れると正常に動作します。
しかし、この記述を消すと動作しません。
###上手く動作するコード
window.addEventListener("message", receiveSize, false); function receiveSize(e) { if (e.origin === "https://file003.shop-pro.jp/") console.log("aaa") document.getElementById("iframe-contents").style.height = e.data + "px"; }
「document.getElementById("iframe-contents").style.height = e.data + "px";」は動作しますが、console.logは動作しません。
###動作しないコード
window.addEventListener("message", receiveSize, false); function receiveSize(e) { if (e.origin === "https://file003.shop-pro.jp/") document.getElementById("iframe-contents").style.height = e.data + "px"; }
色々試してみたのですが、原因が全くわかりません。アドバイスお願い致します。
###追記
ifのブロック内で2行目だけ実行されているようです。。。
下記の文だと1行目がスキップされ2行目だけ実行されています。
if (e.origin === "https://file003.shop-pro.jp/") console.log("aaa") document.getElementById("iframe-contents").style.height = e.data + "px"; if (e.origin === "https://file003.shop-pro.jp/") document.getElementById("iframe-contents").style.height = e.data + "px"; console.log("aaa")
1行目と2行目を入れ替えると2行目の「console.log("aaa")」正常に動作します、
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/31 00:45