通过使用loadURL运行JavaScript加载不同的页面 [英] Using loadUrl to run javascript loads different page

查看:2070
本文介绍了通过使用loadURL运行JavaScript加载不同的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用了OAuth的形式,只为dev的目的,我想,以消除用户名和密码打字,所以我加了一些code像这样,当网页加载完成的应用程序:

We have an app that uses a form for oauth, just for dev purposes I want to eliminate typing in the user name and password so I added some code like this for when the page finishes loading:

mWebView.loadUrl("javascript:document.getElementById('UserName').value='" + txtUser.getText()+"'");

但由于某些原因,它不填写表格它使一个新的页面,只是写出txtUser的值,而不是在输入字段填写?为什么以及如何解决这个问题?

But for some reason it doesn't fill in the form it makes a new page and just writes out the value of txtUser instead of filling in the input field? Why and how can I fix this?

推荐答案

如果你看看一个工具,水枪看它做一个匿名函数调用。所以,我不认为在JavaScript精通,但匿名电话似乎是在浏览器认为这是当前页面进行调用本身的关键。因此,尝试此的大致的:

If you look at a tool look Squirt it does an anonymous function call. So I am not that versed in javascript, but that anonymous call seems to be the key in that the browser sees it as the current page is making the call itself. So try this roughly:

mWebView.loadUrl("javascript:(function(){document.getElementById('UserName').value='" + txtUser.getText()+"';})()");

这篇关于通过使用loadURL运行JavaScript加载不同的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆