我有一个 php 页面,其中有一个名为“信息”的按钮。单击此按钮,我将获得一个新窗口。在出现这个小窗口时,我想禁用第一个窗口中的所有操作或点击。这可能吗?
我的代码是: 父文件:
<form method="GET" name="myform" >
<td><input type="radio" name="radioEdit" value="<?php echo $id; ?>" /><?= $id; ?></td>
<input type="submit" value="info" formaction="edit.php" onclick="target_popup(myform,'edit.php')"/>
</form>
<script>
function target_popup(form,page)
{
window.open(page, 'formpopup', 'left=100,top=100,width=600,height=400,menubar,toolbar,resizable');
form.target = 'formpopup';
}
</script>
编辑.php:
<?php
if(isset($_GET['radioEdit']))
{
$n=$_GET['radioEdit'];
echo"n=$n";
}
else
{
echo"fail";
?>
点击信息按钮后会出现这个新窗口,我可以禁用 parent.php 直到新窗口关闭吗?请帮忙。
最佳答案
这是用于 jquery 弹出窗口
弹出消息显示后出现一个透明的 div,并且在该 div 上禁用所有点击事件,因为点击事件仅适用于弹出窗口。我认为这会对您有所帮助:)
<div class="disableRightClick">
</div>
https://jsfiddle.net/kokilajs/w99Mj/64/
============================================= ===============
更新:下面的代码用于 window.open(url) 弹出
为了检查这个解决方案,使用没有服务器 chrome 的 server[localhost] 不起作用,但 FF 可能起作用
父窗口
<style type="text/css">
#disableRightClick{
position: absolute;
min-width:100%;
min-height:100%;
background-color:rgba(1,1,1,0.4);
z-index:99;
display: none;
}
body,html{
margin:0;
padding: 0;
}
</style>
<div id="disableRightClick"></div>
<a href="http://google.com">go to google</a>
<form method="GET" name="myform" >
<td><input type="radio" name="radioEdit" value="<?php echo $id; ?>" /><?= $id; ?></td>
<input type="submit" value="info" formaction="pop.html" onclick="target_popup(myform,'pop.html')"/>
</form>
<script>
var dis = $('#disableRightClick').on("contextmenu",function(e){
alert('click disabled');
return false;
});
dis.on("click",function(e){
alert('click disabled');
return false;
});
function target_popup(form,page)
{
var new_window = window.open(page, 'formpopup', 'left=100,top=100,width=600,height=400,menubar,toolbar,resizable');
form.target = 'formpopup';
new_window.onload = click_disable;
function click_disable() {
window.document.getElementById('disableRightClick').style.display = 'block';
}
}
</script>
弹窗(edit.php)
popup window test msg
<script>
window.onbeforeunload = disableparent;
function disableparent() {
window.opener.document.getElementById('disableRightClick').style.display = 'none';
}
</script>
关于javascript - 我们可以禁止点击任何窗口吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29114934/