locked
How do I Trap WebView links that open up in external browser? RRS feed

  • Question

  • In a WebView I am loading pages from the internet and would like when a user clicks a link record the url so I can do an action against the url.

    I know I can add a NavigationStarting handler and set the "args.Cancel" to true and prevent the WebView from visiting the link.

    But how do I do this if the page is set to load the link in a different tab or window. For instance if in the html tag

    <a href=http://bing.com   target="_blank">

    I would like to get these urls as well.

    Thanks,

    Knic



    • Edited by oneeyedelf1 Tuesday, November 5, 2013 7:45 AM clarity
    Tuesday, November 5, 2013 7:43 AM

All replies

  • You'll have to inject javascript into the page to trap these events.

    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, November 5, 2013 2:21 PM
    Moderator
  • The WebView url is from my app's (ms-appx-web///local.html), unfortunately the code that contains these links are in iframes from a different domain. From what I read online I cannot simply inject javascript into those iframes, is there a way to do this? *Note I do not control the code from the iframe in the different domain.
    Tuesday, November 5, 2013 5:44 PM
  • I don't think this is going to work since the page hosting the iframe can't access it's content.  Wouldn't it be easier to surround the webview with XAML content, and directly host the third-party page, so you can then inject javascript into it?

    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, November 5, 2013 7:53 PM
    Moderator
  • Unfortunately I cannot directly host the page in the webview. This is because then I cannot arrange multiple of them in a scrolling auto loading fashion (think images from bing image search). Unfortunately webview is just to heavy and it lags, you can see my post about this at http://social.msdn.microsoft.com/Forums/windowsapps/en-US/31b7faa9-30b1-4c6d-b0f3-d3fe57e08ecd/howto-prevent-lag-when-scrolling-multiple-webviews?forum=w81prevwCsharp

    Any other suggestions?

    Thanks,

    Knic

    Wednesday, November 6, 2013 6:59 AM