我正在尝试使用 UIWebView 登录页面。由于基础设施非常复杂,我正在加载登录页面并手动提交表单(插入 JavaScript)。加载主页后,我想重定向到另一个页面。唯一的问题是,我无能为力让重定向等待主页加载完毕(因为我没有加载提交表单的 View )。有什么办法可以让它等待吗?
我当前的代码
webView.stringByEvaluatingJavaScriptFromString(jScript3) //submit the form
let gradeURL = NSURL(string: "https://redirectpage")!
let gradeRequest = NSMutableURLRequest(URL:gradeURL)
webView.loadRequest(gradeRequest)
谢谢!
最佳答案
我想你可能想从重定向页面获取一些东西。
先设置Delegate,然后使用UIwebViewDelegate函数
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
//do nothing except 4 the redirectURL
if request.URL?.absoluteString.hasPrefix(redirectURL) == false {
return true
}
//detailly handle the query
if let _query = request.URL?.query where _query.condition {...}
}
关于javascript - Swift 等待 UIWebView 中 javascript 的页面加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34552306/