當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


SVG Window.isSecureContext屬性用法及代碼示例

SVG Window.isSecureContext屬性指示上下文是否能夠使用需要安全上下文的函數。

用法:

var isSecure = window.isSecureContext

返回值:這個性質返回布爾值

範例1:在此示例中,我們將使用onclick事件。

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <center> 
        <h1>GeeksforGeeks</h1> 
  
        <button onclick="get()"> 
            Check 
        </button> 
          
        <br><br> 
        <div id="g"></div> 
  
        <svg viewBox="0 0 1000 1000" 
            xmlns="http://www.w3.org/2000/svg"> 
              
            <script type="text/javascript"> 
                function get() { 
                    var g = document.getElementById("g"); 
                      
                    g.innerHTML = " Is it secure?:"  
                            + window.isSecureContext; 
                } 
            </script> 
        </svg> 
    </center> 
</body> 
  
</html>

輸出:



範例2:在此示例中,我們將使用onmouseover事件。

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <center> 
        <h1>GeeksforGeeks</h1> 
  
        <button onmouseover="get()"> 
            Check 
        </button> 
  
        <br><br> 
        <div id="g"></div> 
          
        <svg viewBox="0 0 1000 1000" 
            xmlns="http://www.w3.org/2000/svg"> 
              
            <script type="text/javascript"> 
                function get() { 
                    var g = document.getElementById("g"); 
                      
                    g.innerHTML = " Is it secure?:" 
                        + window.isSecureContext; 
                } 
            </script> 
        </svg> 
    </center> 
</body> 
  
</html>

輸出:

支持的瀏覽器:

  • 穀歌瀏覽器
  • Edge
  • Firefox
  • Safari
  • Opera




相關用法


注:本文由純淨天空篩選整理自taran910大神的英文原創作品 SVG Window.isSecureContext Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。