【问题标题】:Using jQuery to simulate the click of a link - outside of an iframe, which links to another domain?使用 jQuery 模拟链接的点击 - 在 iframe 之外,哪个链接到另一个域?
【发布时间】:2013-01-14 23:10:12
【问题描述】:

在我的脑海中这应该是直截了当的,但经过测试我发现它并不像我想象的那么容易!

我想要做的是单击 iFrame 外部的链接,这将触发动态“快速查看”灯箱,即使在父站点(位于不同域中)内也是如此。

例如:

<a class="quickViewLink" href="#"> VIEW TO PURCHASE </a>

<iFrame src="http://www.google.com/">
  <a class="quickViewLink" href="#"> Clicking this will simulate the click of the link outside of this iframe </a>
</iFrame>

我尝试过 target="_parent" 并尝试使用 jQuery 来定位特定链接,但没有成功。

任何帮助将不胜感激!

编辑:我无法访问 iFrame 之外的网站!(这是我卡住的地方)

【问题讨论】:

    标签: jquery parent target


    【解决方案1】:
    <a class="quickViewLink" href="#"> VIEW TO PURCHASE </a>
    <script type="text/javascript">
        function clickLink() {
            $('.quickViewLink').trigger('click');
        }
    </script>
    <iFrame src="http://www.google.com/">
      <a href="javascript: window.parent.clickLink()" class="quickViewLink"> Clicking this will simulate the click of the link outside of this iframe </a>
    </iFrame>
    

    与 jQuery 一起使用。

    【讨论】:

    • 太棒了!但是我无法访问 iFrame 之外的父站点(非常烦人),无论如何我可以从 iFrame 内部执行此操作吗?
    • 我认为你不能......也许其他人有解决方案,但我认为这是不可能的......
    • 我确信这就是我所需要的!我会看看其他人是否有任何意见,但我认为你可能是对的。我可能有一些令人信服的事情要做!
    • @LouisXIV 我试过这样 JS $('#btnIframe').click(function(){ $('#filecontainer').attr('src','http://jsfiddle.net/tvshajeer/08kv6jqx/1/'); }); $('#btnlogout').click(function(){ $('#btniframeTest').trigger('click'); }); 它不起作用。 fiddle demo here.
    • 嘿 tvshajeer,我认为你应该提出一个新问题,因为它看起来有点不同。我认为您的目标是不可能的,但也许其他人会为您的问题提供解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多