0

I set the onclick event handler of one button in one of my iframes to add content to the table of another iframe of the same window,I use

var w = parent.frames[1].getElementsByTagName("tr"); 

this function should return a HTMLcollection object which is an Array-like object,but it seems that firefox and chrome can not parse my code because it can not execute

alert("here") ;

I placed after the getelement instruction,does anyone have a idea what is wrong,I am new to Web programming...

2 Answers2

6

The function is getElementsByTagName("tag"); with a 's'.

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
boulaycote
  • 602
  • 1
  • 6
  • 18
  • sorry,I mistyped it here,but I did not mistype it in my code,so there is still something wrong...I think it is related to the frame – liao24hoho Jul 18 '11 at 15:04
0

You need a document object

" iframe.contentDocument" Not Working in IE8 and FF(3.5 and below) any other steps to solve this?

var doc;
var iframeObject = parent.document.getElementById('iframeID'); // MUST have an ID
if (iframeObject.contentDocument) { // DOM
  doc = iframeObject.contentDocument;
} 
else if (iframeObject.contentWindow) { // IE win
  doc = iframeObject.contentWindow.document;
}
if (doc) {
  var rows = doc.getElementsByTagName("tr");
}
else {
  alert('Wonder what browser this is...'+navigator.userAgent);
}

assuming the same domain

Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236