积极答复者
win8 webView

问题
答案
-
Hi 陈坚,
这里我做了个例子上传到SkyDrive你可以参考:http://sdrv.ms/14e8G5y
打开project后如果不点击button,将会在外部做IE跳转,点击Button后,会在WebView内部做连接跳转。
其中我对WebView做了Javascript Inject的操作,把下面这段代码注入到Javascript中
string InsertionScriptString = "function disableLink() { "; InsertionScriptString += "var links = document.links, i, length;"; InsertionScriptString += "for (i = 0, length = links.length; i < length; i++) {"; InsertionScriptString += "links[i].target == '_blank' && links[i].removeAttribute('target');}}";
同时,通过下面的代码把功能注入进去
webview.InvokeScript("disableLink", null);
原理是把target = “_blank” 删除。
以上请参考。
James He
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 cj_tianxingzhe 2013年8月15日 3:36
全部回复
-
Hi 陈坚,
这里我做了个例子上传到SkyDrive你可以参考:http://sdrv.ms/14e8G5y
打开project后如果不点击button,将会在外部做IE跳转,点击Button后,会在WebView内部做连接跳转。
其中我对WebView做了Javascript Inject的操作,把下面这段代码注入到Javascript中
string InsertionScriptString = "function disableLink() { "; InsertionScriptString += "var links = document.links, i, length;"; InsertionScriptString += "for (i = 0, length = links.length; i < length; i++) {"; InsertionScriptString += "links[i].target == '_blank' && links[i].removeAttribute('target');}}";
同时,通过下面的代码把功能注入进去
webview.InvokeScript("disableLink", null);
原理是把target = “_blank” 删除。
以上请参考。
James He
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 cj_tianxingzhe 2013年8月15日 3:36
-
有个问题,就是
Windows.Storage.StorageFile MyWebPageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///HTMLPage1.html")); 实际中,怎么在点击超链接之前获得Uri,上面的Uri是硬编码,有没有一个在navigate之前的事件,让我获取到将要导航的Uri,然后改变html中的target
还有,若是网页中有flash动画,webview也显示不了,怎么解决
- 已编辑 cj_tianxingzhe 2013年8月15日 6:13
-
Hi
Flash,PDF,SilverLight之类需要使用到ActiveX的功能都不能在webview里面使用:
ActiveX controls have made Internet Explorer an incredibly useful tool for applications that need to be widely distributed. However, it has also been an attack vector used by malware developers. In the development of the WinRT APIs, it was decided that the WebView control – like the Immersive Internet Explorer – would not host any ActiveX controls, which is how older versions of IE hosted Flash and Silverlight, for safety and performance reasons. Additionally, although the RTM version of IE10 includes Flash as a built-in feature, this did not make it into the WebView control.
然后我分析了下,你主要有两个问题:
1,如何获取当前页面的编码,可以通过使用下面语句来获取
string MyWebPageString = webview.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;" });
2,如何在WebView完成后加入插入JavaScript代码,可以通过LoadCompleted 事件,这个对应的是win8,如果你的开发在win8.1里面,那么对应的事件就是NavigationCompleted。
需要注意的是,以上的两个必须要等到Load完成之后才能进入到页面内部去搜索对应的位置,然后插入JavaScript。
以上请参考。
James He
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Jamles HezModerator 2013年8月15日 7:24 update
-
Hi 陈坚,
对,是这样的,目前WebView功能并非那么强大,而且问题本身也属于修改页面DOM结构。
我想了下,为了解决跳两次的办法,你可以做一个缓冲器,也就是一个隐藏的WebView,先在隐藏的WebView里面加载页面,然后在你的WebView里面显示,这样可以保证用户只看到一次页面转跳的过程,这个可能会牺牲运行速度。
以上,Best Regards
James He
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
这个目前没有,页面还没有加载完全之前是没有办法获取到页面中的DOM的,如果硬要获取,程序就会报错。
--James He
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.
- 已编辑 Jamles HezModerator 2013年8月16日 7:10 1234