使用jQuery/Javascript从iframe中获取父级的元标记

Get meta tags of parent from iframe using jQuery/Javascript

本文关键字:获取 jQuery Javascript iframe 使用      更新时间:2023-09-26

我有一个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>

.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

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

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