WebView.ScriptNotify 이벤트

정의

WebView 컨트롤에 포함된 콘텐츠가 JavaScript를 사용하여 문자열을 애플리케이션에 전달하는 경우에 발생합니다.

public:
 virtual event NotifyEventHandler ^ ScriptNotify;
// Register
event_token ScriptNotify(NotifyEventHandler const& handler) const;

// Revoke with event_token
void ScriptNotify(event_token const* cookie) const;

// Revoke with event_revoker
WebView::ScriptNotify_revoker ScriptNotify(auto_revoke_t, NotifyEventHandler const& handler) const;
public event NotifyEventHandler ScriptNotify;
function onScriptNotify(eventArgs) { /* Your code */ }
webView.addEventListener("scriptnotify", onScriptNotify);
webView.removeEventListener("scriptnotify", onScriptNotify);
- or -
webView.onscriptnotify = onScriptNotify;
Public Custom Event ScriptNotify As NotifyEventHandler 
<WebView ScriptNotify="eventhandler"/>

이벤트 유형

예제

다음 코드 예제에서는 Windows 8용으로 컴파일된 앱에서 ScriptNotify 이벤트를 사용하는 방법을 보여 줍니다. Windows 8.1 시작해서 AllowedScriptNotifyUris와 관련된 줄을 생략합니다.

public MyPage()
{
    this.InitializeComponent();
    MyWebView.ScriptNotify += MyWebView_ScriptNotify;

    // Here we have to set the AllowedScriptNotifyUri property because we are 
    // navigating to some site where we don't own the content and we want to 
    // allow window.external.notify() to pass data back to the app.
    List<Uri> allowedUris = new List<Uri>();
    allowedUris.Add(new Uri("http://www.bing.com"));
    MyWebView.AllowedScriptNotifyUris = allowedUris;
}

void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
    // Respond to the script notification.
}

설명

호스트된 HTML 페이지는 페이지가 window.external.notify 를 호출하고 문자열 매개 변수를 전달하는 경우 UWP 앱에서 ScriptNotify 이벤트를 발생시킬 수 있습니다.

참고

이 이벤트는 외부 코드에 의해 시작되므로 이벤트 처리기에 배치한 내용에 주의해야 합니다. 악의적인 스크립트가 이 이벤트를 악용하지 않도록 하려면 아래 설명된 대로 신뢰할 수 있는 URI에 대해서만 사용하도록 설정해야 합니다.

Windows 8.1

window.external.notify를 호출할 때 외부 웹 페이지에서 ScriptNotify 이벤트를 발생시킬 수 있도록 하려면 앱 매니페스트의 ApplicationContentUriRules 섹션에 페이지의 URI를 포함해야 합니다. Visual Studio에서 Package.appxmanifest 디자이너의 콘텐츠 URI 탭에서 이 작업을 수행할 수 있습니다. 이 목록의 URI는 HTTPS를 사용해야 하며 하위 도메인 와일드카드(예: "https://.microsoft.com")를 포함할 수 있지만 도메인 와일드카드(예: "https://.com" 및 "https://.")를 포함할 수 없습니다. 매니페스트 요구 사항은 앱 패키지에서 시작되거나 ms-local-stream:// URI를 사용하거나 NavigateToString을 통해 로드되는 콘텐츠에 적용되지 않습니다.

참고

하위 도메인이 하나 이상 있는 경우 각 하위 도메인에 대해 하나의 와일드카드를 사용해야 합니다. 예를 들어 "https://*.microsoft.com"은 "https:// any.microsoft.com"와 일치하지만 "https:// 이"와는 일치하지 않습니다. any.microsoft.com."

이러한 변경 내용은 Windows 8.1 실행하는 경우에도 Windows 8용으로 컴파일된 앱에는 영향을 미치지 않습니다.

AllowedScriptNotifyUris, AnyScriptNotifyUriAllowedScriptNotifyUrisProperty는 Windows 8.1 위해 컴파일된 앱에서 지원되지 않습니다.

Windows 8

이러한 설명은 Windows 8.1 실행되는 경우에도 Windows 8용으로 컴파일된 앱에만 적용됩니다.

Navigate 메서드를 사용하여 WebView 컨트롤에 콘텐츠를 로드하는 경우 앱은 ScriptNotify를 실행할 수 있는 URI 목록이 있는 AllowedScriptNotifyUris 속성을 사용하여 ScriptNotify 이벤트를 수신하도록 옵트인해야 합니다. NavigateToString을 사용하여 콘텐츠를 로드하는 경우 애플리케이션은 옵트인 없이 ScriptNotify 이벤트를 수신합니다. AllowedScriptNotifyUris 속성을 AnyScriptNotifyUri 속성에서 반환된 값으로 설정하여 모든 페이지에서 ScriptNotify 이벤트를 이 WebView 컨트롤에 실행할 수 있음을 나타냅니다.

적용 대상

추가 정보