【问题标题】:Getting access to URL changes in an iframe访问 iframe 中的 URL 更改
【发布时间】:2012-07-16 22:07:05
【问题描述】:

我有一些现有的 JavaScript 代码,我无法更改,它们已加载到 iframe 中。 iframe 中的初始页面是本地页面,但来自 JavaScript 的链接(实际上是 <input type="button"...>'s)转到外部内容。我正在寻找一种方法来更改 iframe 在单击 iframe 中的按钮以转到外部 URL 时所在的主页。

我能否以某种方式访问​​ iframe 中的本地页面 css 类?如果做不到这一点,可以使用 .unload() 代替 .click 吗?我只设法使用 .unload 来捕获父框架中的页面更改。

<iframe name="venueFrame" id="venueFrame" frameBorder="0" src=""><p>Your browser does not support iframes.</p></iframe>
<script>
    function selectVenue(page){
        compleateURL='venuemaps/'+page;
        document.getElementById('venueShadow').style.display="block";
        $("#venueFrame").attr({src:compleateURL});
    }
</script>

【问题讨论】:

    标签: jquery url dom iframe parent


    【解决方案1】:

    没有看到任何代码很难知道,但是您可以通过这样做来绑定到iframe上的点击

    $('#iframe').bind('click', function(e) {
        //Stuff to do
    });
    

    只要点击 iframe 内的任何内容,就会发生这种情况。如果您尝试根据链接更改特定内容,那么您将很难做到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-26
      • 1970-01-01
      • 2012-06-27
      • 2011-11-26
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      • 2013-01-20
      相关资源
      最近更新 更多