【问题标题】:Get meta tags of parent from iframe using jQuery/Javascript使用 jQuery/Javascript 从 iframe 获取父级的元标记
【发布时间】:2013-07-10 23:02:23
【问题描述】:

我有一个包含以下内容的 HTML 文件

<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" name="viewport">

<meta content="desc goes here" name="description">
<meta content="auth name" name="author">
<title>builder 1.0</title>
</head>
<body>
<iframe width="100%" height="100%" src="http://domain.com/a.html" name="cxsideframe" scrolling:'no';="" id="frame1" style="overflow:hidden;">
</iframe>
</body></html>

a.html的内容是

<html>
<head>
<meta charset="utf-8">
<title>builder v1.0</title>


<body>
<img src="http://example.com/images/01._V397411194_.png" style="display:none" alt=""/>
<img src="http://example.com/images/V386942464_.gif" style="display:none" alt="" />
</body></html>

我需要知道一种使用jQuery或javascript从父页面获取父页面html的元标记和图像列表的方法。

$('meta[name=author]').attr("content");       does not work for me

【问题讨论】:

  • 这可能会有所帮助:stackoverflow.com/a/1133526/921204 - 将 $(elementid).attr(attributeName) 替换为 $('meta[name=author]').attr("content")
  • @techfoobar 它返回 undefined
  • 您使用的是哪个版本的 jquery?
  • @Thirumalaimurugan 1.7.1
  • @Zubin 从 jQuery 1.6 开始,.prop() 方法提供了一种显式检索属性值的方法,而 .attr() 检索属性。将attr 更改为prop 并检查

标签: javascript jquery dom html-parsing


【解决方案1】:

可以使用document.getElementsByTagNames,然后操作返回的数组

 var metas = document.getElementsByTagName("meta");
 var imagesOnPage = document.getElementsByTagName("img")

【讨论】:

  • 由于是来自 iframe,所以我得到一个空白结果
猜你喜欢
  • 2018-05-08
  • 2017-08-08
  • 2010-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多