none
[U8.1][HTML] X-ms-webview events never firing RRS feed

  • Question

  • Hello, I'm having troubles with listening to events supposedly produced by x-ms-webview in a Javascript app. It seems like they are never being fired. Underneath is my code:

    var myIframe = document.getElementById("webview");
    myIframe.addEventListener("mswebviewnavigationcompleted", function () { console.log(this) });
    myIframe.src = 'http://bing.com';

    I've tried most events listed in the API.

    This is part of a Cordova app, if that makes any difference. 


    Tuesday, June 9, 2015 10:34 AM

Answers

  • It seems the problem was that the examples are incorrect for each of the events in x-ms-webview.

    For example in the MSWebViewDOMContentLoaded event documentation the javascript example reads like this:

    function handler(eventInfo) { /* Your code */ }
     
    // addEventListener syntax
    x-ms-webview.addEventListener("mswebviewdomcontentloaded", handler);
    x-ms-webview.removeEventListener("mswebviewdomcontentloaded", handler);

    Instead the events need to be camel-case like this:

    function handler(eventInfo) { /* Your code */ }
     
    // addEventListener syntax
    x-ms-webview.addEventListener("MSWebViewDOMContentLoaded", handler);
    x-ms-webview.removeEventListener("MSWebViewDOMContentLoaded", handler);

    Wednesday, June 10, 2015 8:07 AM

All replies

  • Hi Maarten - are you able to reproduce the problem in a plain Universal app?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, June 9, 2015 12:07 PM
  • It seems to do the exact same thing, or nothing rather in a plain universal app, with any of the events.

        <x-ms-webview id="webview" src="https://bing.com" style="width:100%; height:100%; ; top:0; bottom:0; left:0; right:0;"></x-ms-webview>
        <script type="text/javascript">
            var myIframe = document.getElementById("webview");
            myIframe.addEventListener("mswebviewnavigationstart", function () { console.log(this) });
            myIframe.src = 'https://google.com';
        </script>

    Tuesday, June 9, 2015 1:20 PM
  • It seems the problem was that the examples are incorrect for each of the events in x-ms-webview.

    For example in the MSWebViewDOMContentLoaded event documentation the javascript example reads like this:

    function handler(eventInfo) { /* Your code */ }
     
    // addEventListener syntax
    x-ms-webview.addEventListener("mswebviewdomcontentloaded", handler);
    x-ms-webview.removeEventListener("mswebviewdomcontentloaded", handler);

    Instead the events need to be camel-case like this:

    function handler(eventInfo) { /* Your code */ }
     
    // addEventListener syntax
    x-ms-webview.addEventListener("MSWebViewDOMContentLoaded", handler);
    x-ms-webview.removeEventListener("MSWebViewDOMContentLoaded", handler);

    Wednesday, June 10, 2015 8:07 AM