Webbrowser in Windows Phone does not support opening new windows.That is, when you click a hyperlink with target = "_ blank" on the page, the hyperlink will not be opened. How can this problem be solved?
The idea is: we can replace all target = "_ blank" on the page with target = "_ Self", so that when you click the hyperlink, this link will be opened in the original webbrowser.
So how to implement it?
There are two ideas:
1. After the webpage is loadedSource codeGet it, and replace this string (this will be a little problem, think about Chinese ...)
2. When the webpage is loaded, JavaScript is called.CodeAnd use js to implement replacement.
This article will briefly introduce the implementation of the second method. As for the first method, you can study it on your own.
Webbrowser has an isscriptenabled attribute. When we set it to true, we can call the front-end JS function in the post code. The Code is as follows:
Webbrowser1. Invokescript("Test ");
Webbrowser1.invokescript ("Test2", "1 ");
The parameter is a function name or a function name plus a parameter.
So we can use this method in the event of webpage content loading to replace target = "_ blank" with target = "_ Self". The specific code is as follows:
In this way, after the web page is loaded, the target = "_ blank" in the original page has been replaced with target = "_ Self", so that you can click the hyperlink normally and then go to webbrowser.