如何创建用于打开iframe链接的直接链接



我被困在为iframe页面项目链接创建WordPress菜单链接 - 这就是我们在iframe中打开链接时使用的

<a href="https://..." target="iframe-id">Open in iFrame</a>

我想把这个链接提供给我的一个WordPress菜单链接。我该怎么做?请指导。谢谢!

你可以试试这个:

jQuery(document).ready(function($){
$(document).on('click','[target="iframe-id"]',function(){
$("#load-iframe").attr('src', $(this).attr('href')).show();
});
});
iframe{
width:100%;
height:450px;
display:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="https://www.lipsum.com/" target="iframe-id">Open in iFrame</a>
<!-- Put This Somewhere on the page -->
<iframe id="load-iframe" src="">
<p>Your browser does not support iframes.</p>
</iframe>

最新更新