将target =“_ top”添加到fancybox iframe内的墨迹 [英] Add target=“_top” to ink that is inside the fancybox iframe

查看:167
本文介绍了将target =“_ top”添加到fancybox iframe内的墨迹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过fancybox iframe访问的页面设置。如何在iframe的父窗口中加载fancybox iframe内的链接?因此,如果用户单击该链接,它将重新加载页面并加载单击的链接。如何在所有链接中添加target =_ top属性?

I have a page setup that is accessed through a fancybox iframe. How can a link that is inside the fancybox iframe, load in the parent window of the iframe? So if the user clicks the link, it will reload the page and load the clicked link. How do I add a target="_top" attribute to the all links?

例如。

$("iframe").on("load", function () {
    $("a").each(function() {
      $(this).attr('target', '_top');
   });
}) 


推荐答案

假设您的子页面中有常规链接,例如:

Assuming that in your child page you have regular links like :

<p>This link opens <a href="http://google.com">GOOGLE</a></p>
<p>This link opens <a href="http://jsfiddle.net">JSFIDDLE</a></p>
<p>This link opens <a href="http://stackoverflow.com">STACKOVERFLOW</a></p>

您可以设置属性 onclick 使用fancybox afterShow 回调从父页面中的每个链接。然后,将 parent.location.assign() $。fancybox.close()设置为 onclick 属性值。

You could set the attribute onclick to each link from within the parent page using the fancybox afterShow callback. Then, set parent.location.assign() and $.fancybox.close() as the onclick attribute value.

这是您父页面的代码:

jQuery(document).ready(function ($) {
    $(".fancybox").fancybox({
        type : "iframe",
        afterShow : function () {
            $(".fancybox-iframe").contents().find("a").attr("onclick", "parent.location.assign(this.href);parent.$.fancybox.close();")
        }
    });
}); // ready

现在,iframed页面上的每个链接都将关闭fancybox并加载引用的URL父(上)页。

Now, each link on the iframed page will close fancybox and load the referred URL in the parent (top) page.

注意


  • 我们需要在 .assign()方法中传递 this.href ,该方法对应于 href 每个链接的值。

  • 我们不需要在子页面中包含jQuery。

  • 使用iframe需遵守同源政策

  • We need to pass this.href within the .assign() method, which corresponds to href value of each link.
  • We don't need to include jQuery in the child page.
  • Working with iframes is subject to the Same-origin policy

参见演示: http://www.picssel.com/playground/jquery/openURLfromChildPage_13apr14.html

See demo : http://www.picssel.com/playground/jquery/openURLfromChildPage_13apr14.html

这篇关于将target =“_ top”添加到fancybox iframe内的墨迹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆