首页 文章

将iframe链接加载到父窗口?

提问于
浏览
25

我有这个iframe代码:

<iframe src="http://www.example.com" border="0" framespacing="0" marginheight="0" marginwidth="0" vspace="0" hspace="0" scrolling="yes" width="100%" frameborder="0" height="100%"></iframe>

我正在尝试做的是..当我点击iframe页面中的任何链接..然后我将转到它并且页面将加载,我将从当前页面到iframe链接作为新页面 .

target="_self" 之类的东西 - 不像普通的iframe那样会在浏览器本身没有任何变化的情况下进入这个链接 .

示例:iframe src:http://www.w3schools.com

当我在iframe页面中单击"Learn HTML"时...然后我将转到http://www.w3schools.com/html/default.asp,我的浏览器URL也将更改为它 .

所以我只是点击了iframe里面的一个链接,我就去了 .

有任何想法吗?

5 回答

  • 1

    是的,您可以使用target="_parent"来实现此目的 .

    “target =”_ parent“打开父框架中的链接文档 . ”

    Example:

    <a target="_parent" href="http://example.org">Click me!</a>
    

    Edit:

    如果那不起作用,你可以尝试 _top

    <a target="_top" href="http://example.org">Click me!</a>
    

    base target

    <base target="_parent" />
    

    或者 window.top.location 在JavaScript中:

    window.top.location = "http://example.com";
    
  • 37

    你要找的是 <a href="..." target="_parent">

    _parent 将使其转到父框架

    _top 将导致它进入最高级别 .

    _parent_top 应该适用于您的目标 .

  • 6

    您可以使用javascript动态地将目标添加到链接,类似这样 .

    function onLoadIF(frame)
    {
        var elements = frame.getElementsByTagName('a'),
            len = elements.length;
    
        while( len-- ) {
            elements[len].target = "_parent";
        }
    }
    

    然后将onload =“onLoadIF(this)”添加到iframe .

  • 5

    是的,只需在链接上添加 target="_parent" 并将其加载到主页面上 .

  • 13

    如果网站在iframe中打开,则会重定向到主网站

    <script>
        if (window.top.location != window.self.location) {
            top.window.location.href = window.self.location;
        }
    </script>
    

相关问题