【问题标题】:Grab SRC Value from Inside Iframe从 Iframe 内部获取 SRC 值
【发布时间】:2011-12-26 00:32:46
【问题描述】:

这可能有点难以解释,但我整晚都在思考它,我似乎无法正确理解。

我的网站上运行了一个 iframe,iframe 内部是一张图片一个链接。这是我从 FireBug 中抓取的 iframe 内部的内容。

<head>
<body style="background-color:transparent; margin:0; outline-offset:0;">
<div style="text-align:center;">
<a onclick="document.location.reload(true);" href="http://randomwebsite.com/THE-URL-I-NEED" target="_blank">
<img width="160" height="600" border="0" src="http://randomwebsite.com/RANDOM-IMAGE.JPG">
</a>
</div>
</body>
</html>

现在,我需要获取该单个 URL 并使用 Jquery 将其设置为变量,然后将变量设置为 iframe 外部的链接。所以我在想这样的事情。

<a id="myiframelink" href=""></a>
<script>$("#myiframelink").attr("href","URL-FROM-INSIDE-IFRAME");</script>

【问题讨论】:

    标签: javascript jquery iframe


    【解决方案1】:

    如果嵌入的 iframe url 与您的域不同,则无法获取该 url。否则,您可以使用类似

    $($('iframe')[0].contentWindow.document.body).search("a").attr('href')
    

    【讨论】:

    • 即使框架已满载也不可能?像这样? $("#myiframelink").attr($('#iframeid')[0].contentWindow.document.body).search("a").attr('href')
    猜你喜欢
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    相关资源
    最近更新 更多