在后台选项卡中打开链接,在当前选项卡中打开模态



我的代码:

//html
<?php
$sql  = "SELECT * FROM table ORDER BY `id` DESC";
$stmt =$DBConnect->query($sql);
while ($row = $stmt->fetch()) { ?>
<a href="<?php echo $row['link']; ?>" class="link" data-toggle="modal" data-target="#<?php echo $row['id']; ?>" onclick="window.open(this.href, '_blank', 'location=yes,height=570,width=430,scrollbars=yes,status=yes');">
<?php include "modal.php"; } ?>
// modal.php
<div id="<?php echo $row['id']; ?>" class="modal fade code-modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
...
</div>
<div class="modal-body">
...
</div>
</div>
</div>
</div>

在该代码中,modal在同一选项卡中弹出,链接<?php echo $row['link']; ?>在新窗口中打开。

我的预期输出是,模态应该在当前选项卡中打开并保持在同一选项卡中,链接<?php echo $row['link']; ?>应该在当前窗口的后台选项卡中打开。

我该怎么做?

您可以添加一个将被隐藏的新标签,该标签包含应该在后台打开的链接:

<a href="your_link" target="_blank" class="hidden new_tab_link"></a>

在js:中

var myModalEl = document.getElementById('myModal')
myModalEl.addEventListener('show.bs.modal', function (event) {
// do something like $('.new_tab_link').click()
})

最新更新