将href加载到iframe,但在父窗口中将其定位

时间:2013-10-12 20:42:57

标签: javascript jquery html 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,它只会在高处生长,不能缩小到更小的高度(这就是我的问题here,我想要实现的就是在asp.net中的MasterPage行为。

1 个答案:

答案 0 :(得分:1)

这是可能的,您可以使用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();
   });
});
相关问题