WebView 와 js 가 호출 된 구덩이

6232 단어
public class MainActivity extends AppCompatActivity {
  private WebView mWebView = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    showWebView();
}

private void showWebView() {

    mWebView = (WebView) findViewById(R.id.mWebView);
    WebSettings webSettings = mWebView.getSettings();
    //   android     js   
    webSettings.setJavaScriptEnabled(true);
    mWebView.loadUrl("file:///android_asset/hello.html");

    //           ,  hello.html      ,      
  //        String content = "{\"content\":\"\\u003cdiv\\u003e\\u003cp\\u003e     NEXON     RPG    《    》 7 28  iOS/Android      !\\u0026nbsp;\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201607/14697849067464_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"2\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e          、        “   ”  RPG  ,                            。\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057507557_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"3\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057538582_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"4\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057587465_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"5\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057613407_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"6\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e         ,     2                   。\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201607/14697850097742_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"4\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e    :\\u003ca href\\u003d\\\"http://mobile.nexon.co.jp/fwt\\\"\\u003ehttp://mobile.nexon.co.jp/fwt\\u003c/a\\u003e\\u003c/p\\u003e\\u003cp\\u003e\\u003cbr/\\u003e\\u003c/p\\u003e\\u003c/div\\u003e\",\"title\":\"  RPG    《    》    \"}
"; // mWebView.loadUrl("javascript: showHtmlcallJava2(" + content + ")"); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // ,hello.html 。 String content = "{\"content\":\"\\u003cdiv\\u003e\\u003cp\\u003e NEXON RPG 《 》 7 28 iOS/Android !\\u0026nbsp;\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201607/14697849067464_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"2\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e 、 “ ” RPG , 。\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057507557_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"3\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057538582_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"4\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057587465_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"5\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057613407_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"6\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e , 2 。\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201607/14697850097742_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"4\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e :\\u003ca href\\u003d\\\"http://mobile.nexon.co.jp/fwt\\\"\\u003ehttp://mobile.nexon.co.jp/fwt\\u003c/a\\u003e\\u003c/p\\u003e\\u003cp\\u003e\\u003cbr/\\u003e\\u003c/p\\u003e\\u003c/div\\u003e\",\"title\":\" RPG 《 》 \"}
"; mWebView.loadUrl("javascript: showHtmlcallJava2(" + content + ")"); } }); }

}
그 중의 hello. html 는 다음 과 같다.


    
    
    
    
    
    
    
    
    

    
    
    
    

    jsandroid_test
    
    //       android   HtmlcallJava2()
    function showHtmlcallJava2(json){

        $(".news-content-block .title h1").html(json.title);
        $(".news-content-block .news-content").html(json.content.replace(/_ueditor_page_break_tag_/g,""));

        //  android    
        window.jsObj.HtmlcallJava2(str+","+str1);
        }

    





좋은 웹페이지 즐겨찾기