How to transfer values between HTML files in WebView within the Android system

Source: Internet
Author: User

Before doing the transfer of the value between the HTML, using the suffix question mark method, namely: a.html?id=1 this form.
Then work hard to finish all the pages and after the PC-side browser debugging success, packaged into Android, put all the HTML files into the assets folder, and through the WebView to access the homepage index.html. With Android studio configured and downloaded to the machine (Android version is very low) inside, the operation is also very successful ...
However, one big problem is that the suffix question mark is not compatible with the method of transferring the values. Not accessible on Android devices with. Web site address. All of a sudden I was so mad ...
Baidu on the Internet a lot of information, found that android3.0 after the support of this way.
Reference: http://blog.csdn.net/wenfengzhuo/article/details/7924807

To implement this feature, it seems that you have to go through the app ... But that means writing code again and debugging Android.
Reference: http://www.oschina.net/question/931234_2142629
Http://zhidao.baidu.com/link?url=8paS-GxU7Ma2kY3zJr91O1M0UoRVoagFoHofuOqEGDHqHlCmfBtTDdfjKI-HpeNs4OJxhJxK80j3-3TNZft9bq
http://blog.csdn.net/li_li_lin/article/details/39484721
http://blog.csdn.net/qduningning/article/details/43411765
http://blogs.360.cn/360mobile/2014/09/22/webview%E8%B7%A8%E6%BA%90%E6%94%BB%E5%87%BB%E5%88%86%E6%9E%90/
http://blog.csdn.net/kevinscsdn/article/details/52241334

So, think of a way .... Simple and convenient: localstorage.
Only need to declare in Mainactivity.java WebView can use Localstorage:

Webview.getsettings (). Setjavascriptenabled (true);
Webview.getsettings (). Setdomstorageenabled (True);

Then you just have to write JS, and you don't need to go through Android.

Attached JS code:

A.html

<body>
<a href= "b.html" onclick= "content ()" > Submit jump Value </a> 
</body>
<script Type= "Text/javascript" >  
            window.onload = function () {  

            }  

            function content () {                    
                var zhi1 = document.getElementById ("Id1"). Value;  
                var zhi2 = document.getElementById ("Id2"). Value;  
                Localstorage.setitem ("1", ID1);  
                Localstorage.setitem ("2", ID2);              
            }  

B.html

<script type= "Text/javascript" > Window.onload=function () {  
                var A=localstorage.getitem ("1");  
                var B=localstorage.getitem ("2");  
                document.getElementById ("Jieshouzhi1"). Value=a;  

            document.getElementById ("Jieshouzhi2"). Value=b; } </script> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.