Javascript 从android webview中的网页重定向
所以我带着这张表格。我想在我的网络视图中包含它Javascript 从android webview中的网页重定向,javascript,android,html,webview,url-redirection,Javascript,Android,Html,Webview,Url Redirection,所以我带着这张表格。我想在我的网络视图中包含它 <html> <head> <meta name="viewport" content="user-scalable = yes"> <link rel="stylesheet" href="assets/css/bootstrap.css"> </head> <body> <!--LOGIN FOR
<html>
<head>
<meta name="viewport" content="user-scalable = yes">
<link rel="stylesheet" href="assets/css/bootstrap.css">
</head>
<body>
<!--LOGIN FORM -->
<div class="border" Style="width:100%;max-width:100%;height:100%;">
<div class="bs-example form-horizontal">
<div id="msg-info" style="display:none;" ></div>
<form class="form-horizontal" id="login-user" name="login-user" action='' method="POST">
<fieldset>
<div id="legend">
<legend class="">Reigstered Members Login<span class="text-center"> <img id="spinner" src="images/loading.gif" style="display:none;"/></span></legend>
</div>
<div class="control-group">
<!-- Username -->
<label class="control-label" for="username" style="text-align:left;"><strong>User ID</strong> <small>(It can be Account No, Mobile No or Email)</small></label>
<div class="controls">
<input type="text" id="username" name="username" placeholder="" class="form-control">
</div>
<!-- Password-->
<label class="control-label" for="password" style="text-align:left;"><strong>Password</strong></label>
<div class="controls">
<input type="password" id="password" name="password" placeholder="" class="form-control">
</div>
<label class="control-label" for="password"> </label>
<!-- Button -->
<div class="controls">
<input type="button" id="login-btn" name="login" class="btn btn-success" value="Login »" />
</div>
</div>
</fieldset>
</form>
</div>
<p><font color="red">Note:</font> Those of you who have not yet registerd can register from here, Note you have to update your mobile no with the society so that registration can be completed</p>
</div>
<br><br><br><br>
<script>
$("#login-btn").click(function(){
validateForm();
});
$("#login-user").keypress(function(event){
if(event.keyCode == 13 || event.which == 13){
validateForm();
}
});
function validateForm(){
var flag=true;
if($("#username").val()==''){
$("#msg-info").addClass("alert alert-danger");
$("#msg-info").html('Enter valid User ID.');
$("#msg-info").show("slow");
flag=false;
return false;
}
if($("#password").val()==''){
$("#msg-info").addClass("alert alert-danger");
$("#msg-info").html('Enter valid Password.');
$("#msg-info").show("slow");
flag=false;
}
if(flag){
$("#msg-info").hide("slow");
//
$('#spinner').show();
jQuery.post('validations/loginStore.php', $('form[name=login-user]').serialize(), function(data) {
data=JSON.parse(data);
$("#msg-info").removeClass("alert-danger");
if(data.update){
//redirect to secure page
if(data.role=='admin'){
window.open('app/dashboard.php?page=societylist&profile=dash', '_parent');
} else {
window.open('app/dashboard.php?page=home', '_parent');
}
} else {
$("#msg-info").addClass("alert alert-danger");
}
if(typeof(data.msg)!='undefined' && data.msg !='' && !data.update){
$("#msg-info").html(data.msg);
}
$("#msg-info").show();
$('#spinner').hide();
});
}
}
</script>
</body>
</head>
如果我做错了什么,或者我遗漏了什么,请帮助我,您似乎遇到了相关问题,如下链接所示。 1. 2. 这可能会对您有所帮助。尝试使用
myWebView.getSettings().setPluginState(PluginState.ON); // this is for newer API's
另外,如果要强制重定向到特定页面,请重写shouldOverrideUrlLoading()
方法
@Override
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
这将在加载网页后立即加载url。您还可以使用计时器显示静态网页,然后将其重定向到新网页
@Override
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
// do your handling codes here, which url is the requested url
// probably you need to open that url rather than redirect:
view.loadUrl(url);
return false; // then it is not handled by default action
}
});