다음을 통해 공유


HttpCapabilitiesBase.JavaScript 속성

정의

주의

The recommended alternative is the EcmaScriptVersion property. A Major version value greater than or equal to 1 implies JavaScript support. http://go.microsoft.com/fwlink/?linkid=14202

브라우저에서 JavaScript를 지원하는지 여부를 나타내는 값을 가져옵니다.

public:
 property bool JavaScript { bool get(); };
[System.Obsolete("The recommended alternative is the EcmaScriptVersion property. A Major version value greater than or equal to 1 implies JavaScript support. http://go.microsoft.com/fwlink/?linkid=14202")]
public bool JavaScript { get; }
[<System.Obsolete("The recommended alternative is the EcmaScriptVersion property. A Major version value greater than or equal to 1 implies JavaScript support. http://go.microsoft.com/fwlink/?linkid=14202")>]
member this.JavaScript : bool
Public ReadOnly Property JavaScript As Boolean

속성 값

Boolean

브라우저에서 JavaScript를 지원하면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

특성

예제

다음 코드 예제에서는 브라우저에서 JavaScript를 지원하는지 여부를 확인하는 방법을 보여 줍니다.

<%@ page language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Page_Load(Object Sender, EventArgs e)
    {
        CheckBrowserCaps();
    }

    void CheckBrowserCaps()
    {
        String labelText = "";
        System.Web.HttpBrowserCapabilities myBrowserCaps = Request.Browser;
        if (((System.Web.Configuration.HttpCapabilitiesBase)myBrowserCaps).JavaScript)
        {
            labelText = "Browser supports JavaScript.";
        }
        else
        {
            labelText = "Browser does not support JavaScript.";
        }

        Label1.Text = labelText;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Browser Capabilities Sample</title>
</head>
<body>
    <form runat="server" id="form1">
        <div>
            Browser Capabilities:
            <p/><asp:Label ID="Label1" Runat="server" />
        </div>
    </form>
</body>
</html>
<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        CheckBrowserCaps()
    End Sub

    Function CheckBrowserCaps()

        Dim labelText As String = ""
        Dim myBrowserCaps As System.Web.HttpBrowserCapabilities = Request.Browser
        If (CType(myBrowserCaps, System.Web.Configuration.HttpCapabilitiesBase)).JavaScript Then
            labelText = "Browser supports JavaScript."
        Else
            labelText = "Browser does not support JavaScript."
        End If

        Label1.Text = labelText

    End Function 'CheckBrowserCaps
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Browser Capabilities Sample</title>
</head>
<body>
    <form runat="server" id="form1">
        <div>
            Browser Capabilities:
            <p/><asp:Label ID="Label1" Runat="server" />
        </div>
    </form>
</body>
</html>

설명

브라우저에서 JavaScript를 지원하지만 보안 설정을 통해 스크립팅을 사용하지 않도록 설정하면 속성이 JavaScript 반환 true 되지만 브라우저에서는 스크립트가 실행되지 않습니다.

적용 대상