【问题标题】:javascript jquery, web developmentjavascript jquery, 网页开发
【发布时间】:2016-02-01 23:00:15
【问题描述】:

当我使用 lumextech.com 搜索并移动到其他网页时,我正在使用 iframe 将 lumextech.com 作为默认 src 在框架中加载但仍然在 iframe src 它的显示 lumextech.com 只有我想要捕获已在 iframe... 中加载的页面的 url。注意:我在 lumextech.com 上没有控制权...。

我的代码:

<! DOCTYPE html>

<html>
    <head>
    <script type="text/javascript" src="jquery.min.js"></script>
    </head>

    <body>
                <section>
                    <h3> welcome to Iframe</h3>                      

                    <script type="text/javascript">


                        $(function(){
                            $('#submit').click(function(){
                               $url = $('#iframeContent').attr('src');
                               $('#demo').html($url);                               
                            });
                        });


                    </script>

                    <input type="submit" id="submit" value="showUrl"/> 
                    <div id="demo"></div> 

                    <iframe id="iframeContent" src="http://lumextech.com" style="min-height: 500px; min-width: 500px;"></iframe>               


                </section>
    </body>

</html> 

【问题讨论】:

  • 同源策略限制阻止了对 iframe 的此类访问
  • 应该有办法........!!!!!!!!!

标签: javascript jquery


【解决方案1】:

您的 src 插入函数中有错字。字符串中的额外空格。好好处理这个Codepen

$('#frameid').attr('src', 'http://lumextech.com/'); 

【讨论】:

  • 好的,我删除了空间但是主要问题是什么......我怎样才能得到当前的网址............
  • 应该...给我秒
  • 是的,我的坏看起来不行。祝你好运
  • contentWindow.location.herf 仅在 iframe 位于同一域中但我在不同域中工作时才有效……我认为这是不可能的…………浏览器不会授予该权限........
猜你喜欢
  • 1970-01-01
  • 2013-09-18
  • 1970-01-01
  • 2016-03-03
  • 1970-01-01
  • 2020-04-15
  • 2011-08-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多