2016-09-25 8 views
0

index.htmlを <object id="battle" data="battle.html"></object>Htmlの<object>、外

私が表示したいアニメーションを持っているからjavascriptの検出を読みますが、アニメーションはフィンランドのときに私はそれを閉じたいです。 私は、Webページが表示されなくなって試してみましたが、それは仕事をしましたが、それの後に画面がunclickableた

battle.html document.getElementById("battlebody").style.display="none"; !The image!アニメーションが行われたときにこのコードが再生されます。基本的には、私はそれの周りに境界線を作り、目に見えない間はどこにいるかを伝えました。

私が行ったように、battle.htmlではなく、index.htmlの<object>マークアップを編集することが可能かどうかは疑問でした。

例 index.htmlを

<body> 
<object id="battle" data="battle.html"></object> 
</body> 

battle.html

<body> 
    <button id="" onclick="closing(); ">close</button> 
    <script> 
    function closing() { 
    window.close() 
    </script> 
</body> 

私はちょっと物体が近いようにしたいが、それはそのように動作しませんので、オブジェクトを作るdisplay:none;が、そのためには、そのjsコードをindex.htmlに追加する必要がありますが、index.htmlには読み込まれません。<object>

+0

plsはバイオリンを作る.. –

+0

@Bla ...することができませんので、フィドルのみ1 htmlページを使用します。 – Bamuel

+0

'object id =" battle "' ... 'document.getElementById(" battlebody ")。style.display =" none ";' ... 2つの異なるIDが...なぜですか?あなたは 'document.getElementById(" battle ")を試してみましたか?style.display =" none ";' –

答えて

2

window.parent.postMessageメソッドを使用できます。

ターゲットページ

<html> 
<body> 
    <script> 
    setTimeout(function() { 
     parent.postMessage('close-me', '*'); 
    }, 2000); 
    </script> 
</body> 
</html> 

index.htmlを

window.onmessage = function(e){ 
 
    if(e.data === 'close-me'){ 
 
    console.log("should remove"); 
 
    obj.parentNode.removeChild(obj); 
 
    } 
 
    };
object{border:1px solid}
<object id="obj" data="data:text/html; charset=utf8, %3Chtml%3E%3Cbody%3E%3Cscript%3EsetTimeout(function()%7Bparent.postMessage('close-me'%2C'*')%3B%7D%2C2000)%3B%3C%2Fscript%3E%3C%2Fbody%3E%3C%2Fhtml%3E"></object>

+0

ありがとう、すぐに試してみます – Bamuel

関連する問題