android webview对document.location.href不支持的有效解决方案

遇到问题了,动动手,就能想到很多方法的。

android的webview不支持的东西很多,这里我们说说

document.location.href="test.html";

window.location.replace("test.html");

这种网页跳转。

alink来模拟点击

function jumpByALink(tourl){
	var aLink = document.createElement("a");
	aLink.style.display = "none";
	aLink.href = tourl;
	aLink.target = '_top';
	document.body.appendChild(aLink);
	setTimeout(function()
		{
			aLink.click();
			document.body.removeChild(aLink);
		}, 10);
	
	window.URL.revokeObjectURL(tourl);
}

还有一种无刷新的处理方法

function jumpByAjax(url){
	$.ajax({
			url: url,
			context: document.body
		}).done(function(data) {
			$("body").html(data);
		})
}
点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注