Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jquery is not working when loading dynamically #13

Open
sirina opened this issue Apr 24, 2013 · 3 comments
Open

jquery is not working when loading dynamically #13

sirina opened this issue Apr 24, 2013 · 3 comments

Comments

@sirina
Copy link

sirina commented Apr 24, 2013

thank you for this project ,In my case i should load the javascript files dynamically after loading the html page instead of writing the script tag directly in the html file but i have problem with jquery.js an error message "undefined" on the log .
this is a sample of code :
this.setWebViewClient(new WebViewClient() {

           public void onPageFinished(WebView view, String url)  
           {  
               /* This call inject JavaScript into the page which just finished loading. */  
              Log.d("call","call java script");

              loadUrl("javascript:(function() { " 
                       +  
                        "var script=document.createElement('script');" +
                        "script.type='text/javascript';" +
                        "script.src='file:///android_asset/jquery.js';" 
                         +
                        "document.getElementsByTagName('head').item(0).appendChild(script);"+  
                        "})()");

             ....

                           }  

please help me .
}

    );
@spdeepa
Copy link

spdeepa commented Apr 27, 2013

You just read the content of html file and append the script code and then load into the webview. This methods works fine for me.

Script Code:

<script src='jquery.js'></script><script src='file:///android_asset/rangy-core.js'></script><script src='file:///android_asset/rangy-serializer.js'></script><script src='file:///android_asset/android.selection.js'></script>

@sirina
Copy link
Author

sirina commented Apr 28, 2013

Can you show some code ?

@spdeepa
Copy link

spdeepa commented May 2, 2013

                            int index=temp.indexOf("</body>");  // temp is the file content return in string
            String s1=temp.substring(0, index);
            String s2=temp.substring(index, temp.length());

                           File f=new File(filepath);  // filepath is the file stored in sdcard path
            webview.loadDataWithBaseURL("file://" + f.getParent() + "/", s1+"<script               src='file:///android_asset/jquery.js'></script><script src='file:///android_asset/rangy-core.js'></script><script src='file:///android_asset/rangy-serializer.js'></script><script src='file:///android_asset/android.selection.js'></script>"+s2,"text/html", "UTF-8", null);  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants