I'm pletely new to javascript and need some assistance. I need to remove a div element from another page which is shown on mine through an <iframe>
.
This is my page's code
<html>
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<head>
<script language="javascript">
</script>
<title>TITLE</title>
<style type="text/css">
body, html
{
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
#content
{
position:absolute; left: 0; right: 0; bottom: 0; top: 0px;
}
</style>
</head>
<body>
<div id="content">
<iframe width="100%" height="100%" frameborder="0" src="PAGE HERE"/>
</div>
</body>
</html>
I need to remove this Div element of another webpage
<div p="removepls">
EDIT
CANNOT EDIT EXTERNAL WEBSITES WHICH ARE NOT HOSTED ON YOUR SERVER
I'm pletely new to javascript and need some assistance. I need to remove a div element from another page which is shown on mine through an <iframe>
.
This is my page's code
<html>
<link rel="icon" href="favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<head>
<script language="javascript">
</script>
<title>TITLE</title>
<style type="text/css">
body, html
{
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
#content
{
position:absolute; left: 0; right: 0; bottom: 0; top: 0px;
}
</style>
</head>
<body>
<div id="content">
<iframe width="100%" height="100%" frameborder="0" src="PAGE HERE"/>
</div>
</body>
</html>
I need to remove this Div element of another webpage
<div p="removepls">
EDIT
CANNOT EDIT EXTERNAL WEBSITES WHICH ARE NOT HOSTED ON YOUR SERVER
Share Improve this question edited Apr 4, 2014 at 19:44 user3499401 asked Apr 4, 2014 at 19:10 user3499401user3499401 431 gold badge1 silver badge4 bronze badges 1- is that 'other page' ing from the same domain as your page? If not, you can't manipulate the contents of it. – DA. Commented Apr 4, 2014 at 19:27
2 Answers
Reset to default 3If the src
of the iframe
is not from the same domain and using the same protocol as the page it is rendered in, then you will not be able to access that content. This violates the same-origin policy
and is a security feature in all modern browsers. If the iframe
contains a page you created with the same domain and protocol, then you can query for the iframe
with jQuery just like any other DOM
element: $('iframe')
or you could also give the iframe
a class or ID and query for it that way.
$('iframe').contents().find("div[p='removepls']").remove();
That should find and remove the oddly attributed div.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744191827a4562468.html
评论列表(0条)