Gets the Dom elements in the iframe page in the Jquery way
- 2020-03-30 02:50:27
- OfStack
Test page code:
Test.html page code
Click the effect of the test button:
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/201405070958173.gif? 20144795832 ">
<html>
<head>
<title>jquery Mode, access iframe page dom The element </title>
<meta name="Author" content=" Sun Qin wave ">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="http://s1.bdstatic.com/r/www/cache/static/jquery/jquery-1.10.2.min_f2fb5194.js"></script>
<script type="text/javascript">
function getIframeDom(){
//Gets the test element of the iframe
var test = $("#frame_1").contents().find("#test");
alert(test.html())
}
</script>
</head>
<body>
<iframe src="file:///C:/Users/SUN/AppData/Local/Temp/non9C34.htm" id="frame_1"></iframe>
<br />
<a href="javascript:getIframeDom();"> To obtain iframe page test Element content </a>
</body>
</html>
Test.html page code
<html>
<head>
<title>iframe page a.html</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<div id="test"> I'm the test page test</div>
</body>
</html>
Click the effect of the test button:
< img SRC = "border = 0 / / files.jb51.net/file_images/article/201405/201405070958173.gif? 20144795832 ">