我在我的Android應用爲什麼我的JavaScript未加載
使用科爾多瓦3.04,這是我的mainactivity代碼
public class MainActivity extends Activity implements CordovaInterface {
CordovaWebView cwv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cwv = (CordovaWebView) findViewById(R.id.cwv);
Config.init(this);
cwv.loadUrl(Config.getStartUrl());
cwv.loadUrl("JavaScript:sayHelloFromJS('hi')");
}
}
和HTML代碼
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function sayHelloFromJS(value) {
alert("JavaScript says: Hello asasasa !!! How are you?");
}
</script>
</head>
<body></body>
</html>
我加載的HTML第一頁然後加載JavaScript爲什麼是HTML加載罰款和JavaScript沒有加載。
不熟悉科爾多瓦,但你試過'cwv.loadUrl(「javascript:sayHelloFromJS('hi')」);'? – nikis
是的,我嘗試了它實際上cwv.loadUrl(「javascript:alert('hi')」);正在工作 – Sar009
我總是使用cordova擴展DroidGap的活動,以及擴展CordovaPlugin的另一個類,但我認爲CordovaInterface基於WebInterface,那麼這就是我如何加載js webView.loadUrl(「javascript:scrollTo(」value 「)」);請注意,這是一個web視圖。 – cesztoszule