在 Windows 8.1 Store HTML5 应用程序中从 webview 检索数据 [英] Retrieving data from webview in Windows 8.1 Store HTML5 app

查看:26
本文介绍了在 Windows 8.1 Store HTML5 应用程序中从 webview 检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Windows 应用商店 HTML5/Javascript 应用程序.作为应用程序的一部分,我需要在网页上调用 Javascript 方法并检索其返回值.

I am developing a Windows Store HTML5/Javascript app. As part of my app I need to invoke a Javascript method on a web page and retrieve its return value.

控件 x-ms-webview 有一个方法 invokeScriptAsync 可以调用 webview 上的脚本.但是,无法从任何方法调用中取回值.

The control x-ms-webview has a method invokeScriptAsync that can invoke a script on a webview. However there is no way of retrieving a value back from any method call.

它似乎也不支持与主机应用程序通信的标准方法,window.external.notify.

It also does not seem to support the standard method of communication with a host app, window.external.notify.

如何从 Windows 应用商店应用 web 视图中的网页检索值?

How can I retrieve a value from a web page in a Windows Store app webview?

推荐答案

RIGHT.

开始变得更有意义了.我在评论中提到的代码:

Starting to make a bit more sense. The code I mentioned in the comments:

var async = webview.invokeScriptAsync('eval', '(function() { return 1337 })()')
async.oncomplete = function(e) {
    console.log(e.target.result)
}
async.start()

日志为空.

但是,将数字 1337 替换为字符串 '1337' 会记录预期值.

However replacing the number 1337 with the string '1337' logs the expected value.

window.external.notify 仍然没有运气 - 但至少可以与 webview 进行某种形式的对话.

Still no luck with doing window.external.notify -- but at least some form of dialogue with the webview is possible.

EDIT window.external.notify 确实 工作,这个答案 最初有错误的事件要监听,但现在是正确的.

EDIT window.external.notify does work, this answer originally had the wrong event to listen for, but it is now correct.

这篇关于在 Windows 8.1 Store HTML5 应用程序中从 webview 检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆