Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

46
Views
(Android) Javascript that is realized twice on WebView

I want to change the text in a GoogleForm via Webview, however the action happens twice.

In the text box, it has the word twice, as if the javascript happens twice.

Would you have an idea? Thanks

public class QuestionnaireFragment extends Fragment  {
//Lancement de l'activité
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState)
{
    View rootView = inflater.inflate(R.layout.fragment_questionnaire, container, false);

    WebView view = (WebView) rootView.findViewById(R.id.webview_questionnaire);
    String url = "LINK GOOGLE FORMS";
    WebSettings webSettings = view.getSettings();
    view.getSettings().setJavaScriptEnabled(true);
    view.loadUrl(url);

    view.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            String js ="javascript:document.getElementsByClassName(\"quantumWizTextinputPaperinputInput exportInput\")[0].focus(); document.execCommand('insertText', false, '" + "WORD"+ "');";

            view.loadUrl(js);

        }
         });
    return rootView;
}

}

The problem

EDIT : I change string by :

String js= "javascript:document.getElementsByClassName(\"quantumWizTextinputPaperinputInput exportInput\")[0].value=\"WORD\";";

But another probllem:

enter image description here

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

In case 1 the word was repeated twice. In case 2 the hint was not going. So, if we use both the lines of code, we can solve the problem. So just do this and it will work:

view.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            String js ="javascript:document.getElementsByClassName(\"quantumWizTextinputPaperinputInput exportInput\")[0].focus(); document.execCommand('insertText', false, '" + ""+ "');";

            view.loadUrl(js);
            
            String js2 = "javascript:document.getElementsByClassName(\"quantumWizTextinputPaperinputInput exportInput\")[0].value=\"WORD\";";
            view.loadUrl(js2);


        }
});
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.