将 href 加载到 iframe,但以父窗口为目标



我有这些代码:

<html>
    <head>
        <title>Iframe</title>
    </head>
<body>
    <a href="somepage.html" target="content">SomePage</a><br/>
    <a href="anotherpage.html" target="content">AnotherPage</a><br/>
    <iframe src="" name="content" height="40%" width="100%"></iframe>
</body>
</html>

如您所见,我有两个链接和一个iframe,我需要的是当我单击SomePage.html链接时,我希望重新加载parent window,然后将SomePage.html加载到iframe中,这可能吗?,谢谢!

编辑:

有一个自动调整大小的 iframe,它只在高度上增长,不能缩小到较小的高度(好吧,这是我的问题,我想要实现的只是 asp.net 中类似母版页的行为。

这是

可能的,您可以使用localStorage它不是完全跨浏览器。快速示例。

$(document).ready(function(){
   if(localStorage.frameURL) {
      $("iframe[name=content]").attr('src', localStorage.frameURL);
   }
   $("[target=content]").click(function() {
     localStorage.frameURL = $(this).attr('href');
     window.location.reload();
   });
});

最新更新