我尝试创建一个系统,用户可以单击链接,并且该链接将加载到同一页面上的弹出窗口中。例如;你有一个 php 链接,例如
<a href='user_message.php?hash=$hash'>$username</a>
如果用户单击该链接,它是否可能会加载到同一页面上的弹出窗口中。请提供任何帮助,我们将不胜感激。
我有能力 PHP
echo"<a href='account.php?hash=$hash>connect</a>
<script type=text/javascript>
$('a').click(function (e) {
e.preventDefault();
$('.boxes').fadeIn('slow').load('user_connect.php?hash=$hash');
});
</script>
我相信我有 prevntDefault
上a
不会让这个工作。
请问这怎么可能
最佳答案
尚未测试,但应该相当简单:
$(document).on('click', 'a', function(e){
e.preventDeafult(); //don't let browser follow the link
var href = $(this).attr('href'); //get the href from original link
var options = "toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=500,height=500";
//Now open the popup
window.open(href, 'NameOfTheWindow', options);
})
请记住,此代码将覆盖您页面上所有链接的行为。如果您只需要在弹出窗口中打开其中一些,请添加类并在处理程序中使用它。
$(document).on('click', 'a.js-open-in-popup', func...
关于javascript - 是否可以在弹出窗口中加载另一个 php 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42140426/