Giter Club home page Giter Club logo

Comments (5)

btate avatar btate commented on July 17, 2024

Wrap your javascript in a try catch block with the error method and see if anything prints.

try{
// Your Code
}
catch(err){
window.TextSelection.jsError(err);
}

That should log an error in eclipse if there's a javascript error somewhere. Good place to start. Aside from that, send me an example of your html content/custom js and I'll try and take a look.

from btandroidwebviewselection.

schildroid avatar schildroid commented on July 17, 2024

Thanks for replying, I have done what you said but still does nothing.

<script type="text/javascript">
        try{
            prom();
        }catch(err){
            window.TextSelection.jsError(err);
        }
        function prom(){
            alert("Function Click!");
        }
</script>

Here's the OnActionItemClickListener with little changes.

mContextMenu.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
            
            public void onItemClick(QuickAction source, int pos,
                int actionId) {
                // TODO Auto-generated method stub
                if (actionId == 1) { 
                    // Do Button 1 stuff
                    Log.i(TAG, "Hit Button 1: ");
                    loadUrl("javascript: prom()"); // Here it is, I'm trying to call a javascript function on the html page provided
                } 
                else if (actionId == 2) { 
                    // Do Button 2 stuff
                    Log.i(TAG, "Hit Button 2");
                } 
                else if (actionId == 3) { 
                    // Do Button 3 stuff
                    Log.i(TAG, "Hit Button 3");
                }
                
                contextMenuVisible = false;
                    
            }
            
        });

No error is being displayed in my Eclipse log cat from a WebView Tag category. Still I did tried pressing the button but the javascript function in my page wont trigger.

Thanks in advance.

from btandroidwebviewselection.

anotherdave avatar anotherdave commented on July 17, 2024

I just had this problem too. If you're building for Android API 17 or greater you need to add the @JavascriptInterface annotation to the methods in TextSelectionJavascriptInterface, otherwise they're not available to the webview and the javascript fails with "TypeError: Object [Object] has no method 'setContentWidth'".

from btandroidwebviewselection.

btate avatar btate commented on July 17, 2024

Thanks for that. I just updated the class on the master branch with the @JavascriptInterface annotation.

from btandroidwebviewselection.

anotherdave avatar anotherdave commented on July 17, 2024

You're welcome, and thanks for the interesting demo.

from btandroidwebviewselection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.