【问题标题】:Android javascript injection, how would I call this function $(document).ready(function(){...})Android javascript注入,我该如何调用这个函数 $(document).ready(function(){...})
【发布时间】:2011-08-04 19:13:38
【问题描述】:

我正在将一些 javascript 注入到 m android webview 中。我只是不完全确定它正在寻找的语法

我想在我的 html 页面中调用这个函数: $(document).ready(function({...})

我的应用中有一个 webview 和 javascript 界面设置。我也启用了 javascript

    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.loadUrl("file:///android_asset/mydocument.html");
    myWebView.addJavascriptInterface(new myJavaScriptInterface(), "jsintector");
    myWebView.loadUrl("javascript:ready()");

javascript:ready() 应该是 android 中调用 html 页面中正确函数的部分。访问此函数的正确语法是什么? $(document).ready(function({...})

(编辑:javascript已经在html中,我只是想强制它从android端运行)

【问题讨论】:

  • html数据里已经有这个函数了?或者你想注入它?
  • 该函数已经在html数据中,我想在android加载不正确的情况下强制执行

标签: java javascript android webview code-injection


【解决方案1】:

尝试搜索之前...

无论如何,最简单的方法是执行以下操作:

  1. load the url into a string
  2. inject the javascript into the string
  3. 使用loaddata将html加载到webview中

【讨论】:

  • 是的,有时即使页面已加载,您也必须强制 android 加载 javascript,如果您搜索,您会发现这是一个常见问题 - 经常没有答案。 javascript已经在html文件中
猜你喜欢
  • 2013-01-16
  • 1970-01-01
  • 1970-01-01
  • 2013-12-15
  • 2010-12-11
  • 2010-12-24
  • 1970-01-01
  • 2017-08-03
相关资源
最近更新 更多