adheus adheus - 1 month ago 5x
C# Question

How can I disallow WebView to open links on the browser in WinRT( target=_blank links )?

I have a WebView on my app and I can't change the html file("target=_blank" link types). But some links on the page makes my app open them on the system browser. How can I disallow this action?



In the NavigationCompleted event handler run this script:

webView.InvokeScriptAsync("eval", new[]
                    var hyperlinks = document.getElementsByTagName('a');
                    for(var i = 0; i < hyperlinks.length; i++)
                        if(hyperlinks[i].getAttribute('target') != null)
                            hyperlinks[i].setAttribute('target', '_self');