Link to home
Start Free TrialLog in
Avatar of codevomit
codevomit

asked on

Remove an element from an iFrame in IE6

Hi,

I need to remove an element from an iFrame in IE6, adding them is not a problem, removing is. I've tried all manor of code from the internet with no prevail, I even attempted to attempted to call a javascript function that inside the iFrame , works on other browsers but not IE6.
Avatar of HainKurt
HainKurt
Flag of Canada image

post a small sample that shows how you add, and the code you tried to remove it... so we can fix it...
Avatar of leakim971
var ref = document.getElementById("iframe_ID").document.getElementById("your_Element_ID");
or
var ref = document.getElementById("iframe_ID").document.getElementsByTagName("TAG_OF_ELEMENT")[INDEX_OF_YOUR_ELEMENT_IN_THE_DOM];

and use :

ref.parentNode.removeChild(ref);
a test script for what leakim971 posted above...
<script>
function test(elm){
  var e = document.getElementById(elm);
  if (e) e.parentNode.removeChild(e); 
}
</script>

<ul>
<li id=liTest1>A
<li id=liTest2>B
<li id=liTest3>C
</ul>

<button onclick="test('liTest1')">Remove A</button>
<button onclick="test('liTest2')">Remove B</button>
<button onclick="test('liTest3')">Remove C</button>

Open in new window

Avatar of codevomit
codevomit

ASKER

HainKurt, I think you may of missed the point, i'm having problem from removing an element that's contained within an iFrame using IE6.
leakim971 I have tried those alread but they do not seem to work with IE6
SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
parent :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<script>
	window.onload = function() {
		var iframe = document.getElementById("iframe_ID");
		var doc = (iframe.contentDocument)?iframe.contentDocument:iframe.contentWindow.document;
		ref = doc.getElementById("your_Element_ID");
		ref.parentNode.removeChild(ref);
	}
</script>
<body>
<iframe id="iframe_ID" width="320px" height="200px" src="child.html"></iframe>
</body>
</html>

Open in new window

child.html :
<html>
<body>
<H3 id="your_Element_ID">codevomit</H3>
</body>
</html>

Open in new window

leakim971's first answer pointed me in the right direction.
Why 250 points? ID:36357086 is a working solution (and it come before your ID:36357125)