swift 如何在 anjular 渲染页面后执行 javascript?
swift how to execute javascript after anjular have rendered the page?
在我的 ios 应用程序中,我使用 WKWebview.evaluateJavaScript() 执行 javascript 以获得 div boundingRect。在我的网页中,我使用 anjularjs 来渲染我的部分页面,页面内容如下,
<body ng-app="home" ng-controller="HomeController" style="min-height:700px;">
<printerinfo></printerinfo>
</body>
<div id="movie" style="border: 1px grey dotted; width: 120px; height: 90px;"></div>
swift
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.wk.evaluateJavaScript("var rect = document.getElementById('movie').getBoundingClientRect(); [rect.x, rect.y, rect.width, rect.height, rect.top, rect.right, rect.bottom, rect.left];") { (result, error) -> Void in
print(result)
}
}
从结果来看,
Optional(<__NSArrayM 0x170251010>(
<null>,
<null>,
120,
90,
0,
120,
90,
0
)
)
boundingRect 位于视口的原点,body 似乎在视口中没有 space。我还以为是网页加载的时候,angualrjs没有渲染body部分。
那么在 anjularjs 使用 swift3 渲染页面后,如何执行 javascript?
非常感谢。
而且我认为使用本机 swift 或 objective-c 来检测页面何时加载是一个糟糕的选择。更灵活有效的方法是在页面加载完成时使用javascript调用原生swift代码。更重要的是,这也适用于特定的 dom 完成加载事件和非常动态的内容。
有关详细信息,请参阅此 。
在我的 ios 应用程序中,我使用 WKWebview.evaluateJavaScript() 执行 javascript 以获得 div boundingRect。在我的网页中,我使用 anjularjs 来渲染我的部分页面,页面内容如下,
<body ng-app="home" ng-controller="HomeController" style="min-height:700px;">
<printerinfo></printerinfo>
</body>
<div id="movie" style="border: 1px grey dotted; width: 120px; height: 90px;"></div>
swift
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.wk.evaluateJavaScript("var rect = document.getElementById('movie').getBoundingClientRect(); [rect.x, rect.y, rect.width, rect.height, rect.top, rect.right, rect.bottom, rect.left];") { (result, error) -> Void in
print(result)
}
}
从结果来看,
Optional(<__NSArrayM 0x170251010>(
<null>,
<null>,
120,
90,
0,
120,
90,
0
)
)
boundingRect 位于视口的原点,body 似乎在视口中没有 space。我还以为是网页加载的时候,angualrjs没有渲染body部分。
那么在 anjularjs 使用 swift3 渲染页面后,如何执行 javascript?
非常感谢。
而且我认为使用本机 swift 或 objective-c 来检测页面何时加载是一个糟糕的选择。更灵活有效的方法是在页面加载完成时使用javascript调用原生swift代码。更重要的是,这也适用于特定的 dom 完成加载事件和非常动态的内容。
有关详细信息,请参阅此