我在html中使用带有提交按钮的表单,打开一个新窗口,单击提交。现在我希望在没有用户干预的情况下关闭这个新窗口。
我试过以下:
<script type="text/javascript">
var newWin;
function newWindow()
{
alert('in newWindow');
newWin=window.open('http://someurl','_blank');
setTimeout(function(){newWin.close()}, 10);
alert('closed..');
}
</script>
但这似乎关闭了新窗口。它仍然保持开放。请帮助。
答案 0 :(得分:0)
您的代码工作正常,只需要花些时间查看该窗口,不需要警报框
wvReport.getSettings().setJavaScriptEnabled(true);
wvReport.getSettings().setAllowFileAccess(true);
wvReport.getSettings().setAllowContentAccess(true);
wvReport.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
Toast.makeText(ReportsViewActivity.this, "Oh no! " , Toast.LENGTH_SHORT).show();
}
});
wvReport.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
if (progress == 100) {
progressBar.setVisibility(View.INVISIBLE);
progressBar.setProgress(0);
} else {
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(progress);
}
}
@Override
public void onReceivedTitle(WebView view, String title) {
}
});
wvReport.loadUrl("http://docs.google.com/viewer?url="+url);