Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify the content of a web page through webview

2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to modify web content through webview". In daily operation, I believe many people have doubts about how to modify web content through webview. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts about "how to modify web content through webview"! Next, please follow the small series to learn together!

There is a requirement. When opening the third-party H5 page through webview, set the card number to the card number input box of the third-party page. The code is complete as follows: package com.example.study2020; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient; public class MainActivity extends AppCompatActivity { String cardNo="6226090213148888"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Get Control WebView mWebView = (WebView) findViewById(R.id.wbPay); WebSettings webset = mWebView.getSettings(); webset.setJavaScriptEnabled(true);//indicates that webview can execute server-side js code webset.setJavaScriptCanOpenWindowsAutomatically(true);//Allow js pop-ups //Visit website //By default, the system will open web pages through mobile browsers. In order to display web pages directly through WebView, you must set mWebView.loadUrl("http://192.168.195.37:8092/springboot/unpay"); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { //Use WebView to load display url view.loadUrl(url); //returns true return true; } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); String jsFunction = "_javascript:function setCardNo() {" + //"alert('123');" + "document.getElementById('cardNo').value='"+cardNo+"';}"; //inject js function view.loadUrl(jsFunction); //call js function view.loadUrl("_javascript:setCardNo();"); } }); }} At this point, the study of "how to modify web content through webview" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 259

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report