在nativescript中获取Webview的内容 [英] get content of webview in nativescript

查看:75
本文介绍了在nativescript中获取Webview的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在页面加载后读取webview的内容?

Is there a way I can read the content of webview after the page is loaded ?

在我的情况下,原因是重定向(例如window.location.replace或window.location.href)在IOS中不起作用,在Android中工作正常.

The reason is redirect (like window.location.replace or window.location.href ) is not working in IOS in my case, works fine in Android.

https://docs.nativescript.org/cookbook/ui/web-view 我可以访问网址,错误.但是如何访问内容?

https://docs.nativescript.org/cookbook/ui/web-view I can access url, error. but how to access content ?

奈良(Narayan)

Narayan

推荐答案

我只是在寻找IOS.我找到了答案并在这里分享.对于Android,我想指出一些线索.

I was only looking for IOS. I found the answer and sharing it here. For Android I would like to point some leads.

if (webView.ios) {
    var webHeader = webView.ios.stringByEvaluatingJavaScriptFromString("document.head.innerHTML").trim();
    console.log(webHeader);

    var webBody = webView.ios.stringByEvaluatingJavaScriptFromString("document.body.innerHTML").trim();
    console.log(webBody);

} else if (webView.android) {
    webTitle = webView.android.getTitle(); //getting the title title
    console.log(webTitle)
}

Android的某些堆栈溢出线索

这篇关于在nativescript中获取Webview的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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