0
我已經有腳本里面的HTML文件。Android webview Javascript功能上下文
<html>
<body>
<script type="text/javascript">
(function(){
var displayAlert = function() {
alert("Start");
};
})();
</script>
</body>
</html>
我把它加載到webView(webView.loadUrl(path_to_html_file)
)。但是當我嘗試通過 webView.loadUrl("javascript:(function(){displayAlert()})();");
調用函數displayAlert時,它無法找到displayAlert函數。我想原因是displayAlert不是全局的。沒有任何方法可以在不使全局displayAlert的情況下實現它。 (通過上下文或引用等)