相关疑难解决方法(0)

使用Javascript在WebView中填写表单

我正试图从Android中的Webview填充Webforms.我已经在这里找到了这段代码:自动填写webview中的字段

String username = "cristian";
webview.loadUrl("javascript:document.getElementById('username').value = '"+username+"';");
Run Code Online (Sandbox Code Playgroud)

不幸的是,我不明白我要打开我要填写的页面.

setContentView(R.layout.web);
final WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(url);
String user="u";
String pwd="p";
mWebView.loadUrl("javascript:document.getElementById('username').value = '"+user+"';document.getElementById('password').value='"+pwd+"';");
Run Code Online (Sandbox Code Playgroud)

当我以这种方式尝试时,网站会显示但表单中没有任何值.

在此先感谢您的帮助

javascript android android-webview

14
推荐指数
2
解决办法
2万
查看次数

未捕获的ReferenceError:myFunction未定义为null:1 webview中的Android异常

我从一个活动调用javascript函数,但我收到Uncaught ReferenceError: myFunction is not defined at null:1错误.这是我的文件

MainActivity.java

package com.example.androidexample;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WebView webview = (WebView)this.findViewById(R.id.webView1);
        WebSettings webSettings = webview.getSettings();

        // Enable Javascript for interaction
        webSettings.setJavaScriptEnabled(true);

        // Make the zoom controls visible
        webSettings.setBuiltInZoomControls(true);

        // Allow for touching selecting/deselecting data series
        webview.requestFocusFromTouch();

        // Set the client
        webview.setWebViewClient(new WebViewClient()); …
Run Code Online (Sandbox Code Playgroud)

javascript android webview

9
推荐指数
1
解决办法
2万
查看次数

Webview数据在Android和HTML页面之间不匹配

我的Android webview中有一个jQuery List View,它从服务器加载数据.我使用HTTP GET响应从服务器数据库获取数据.我用它<body onload="loadRes()">.这是我的方法:

<script>
lastRecord=0;

    function loadRes(){
        $('#sample').html( 'hello' );
        $.get( 
        "queryRestaurantsList.php?lastRecord="+lastRecord,
        function( data ) {
            $('#rest_mesgs').append( data )
            .listview( 'refresh' );
        });
    }
</script> 
Run Code Online (Sandbox Code Playgroud)

但是,我想按特定顺序对此列表进行排序.为此,我从Android代码发送一条POST消息到服务器,其中包含一个像这样的字符串对象:

String list_order ="0012,0002,0003,0001";
Run Code Online (Sandbox Code Playgroud)

list_orderString对象RestaurantID在数据库中表示,它也是主键.这个主键的格式是VARCHAR(4).这是我的php文件:但是,我总是在我的网页视图上收到"仍在工作"的消息,即使我可以通过HttpResponse看到LogCat中已排序列表的HTML

<?
mysql_connect($host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");

echo $_POST['ids'];

if($_POST != null){

$query = "SELECT RestaurantID,Name,Short_Loc,Image_Link,Full_Link,Type FROM Restaurant_Info
          ORDER BY FIND_IN_SET(RestaurantID,'".$ids."')";

$result = mysql_query($query) or die( "Unable to execute query");

while ($row = mysql_fetch_array($result)){
        print '<li id="'.$row['RestaurantID'].'" …
Run Code Online (Sandbox Code Playgroud)

php jquery android webview

3
推荐指数
1
解决办法
751
查看次数

标签 统计

android ×3

javascript ×2

webview ×2

android-webview ×1

jquery ×1

php ×1