答えて

0

あなたはDOMObject.style.backgroundColorとwindow.getComputedStyleがを使用することができます。

<object to set background color of>.style.backgroundColor = window.getComputedStyle(document.getElementsByTagName(“BODY”)[0], null).getPropertyValue("background-color") 

あなたがここにドキュメントを見つけることができます。

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle

0

はこのアクティブを試してみてください同じウィンドウ:

新しいウィンドウで
<script src="https://code.jquery.com/jquery-3.2.1.js" 
     integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" 
     crossorigin="anonymous"></script> 
<style> 
    body { 
     background: #279DDD; 
    } 
</style> 
<p>Click the button to put the new window in the current window.</p> 

<button onclick="myFunction()">Try it</button> 

<script> 
    function myFunction() { 
     debugger; 
    var bgColor=$('body').css('background'); 
    var myWindow = window.open("", "_self"); 
    myWindow.document.write("<p>I replaced the current window.</p>"); 
    myWindow.document.body.style.background = bgColor; 
} 
</script> 

またはこの

これを試してみてください。

 <script src="https://code.jquery.com/jquery-3.2.1.js" 
      integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" 
      crossorigin="anonymous"></script> 
    <style> 
     body { 
      background: #279DDD; 
     } 
    </style> 
    <p>Click the button to put the new window in the current window.</p> 

    <button onclick="myFunction()">Try it</button> 

    <script> 
     function myFunction() { 
      debugger; 
     var bgColor=$('body').css('background'); 
     var myWindow = window.open("", "_self"); 
     myWindow.document.write("<p>I new window.</p>"); 
     myWindow.document.body.style.background = bgColor; 
    } 
    </script> 
関連する問題