0

I have problems with Iframes in Chrome. I have 3 Iframes in a page. I am trying to access elements of one Iframe from another.

I am using with this code:

navFrame = window.parent.frames[0];
lnkTags = navFrame.document.getElementsByTagName('a');

I am getting the following error: Cannot call method 'getElementsByTagName' of undefined

I read in forums that window.parent will not work in chrome. Is it possible to do this differently.

Amit
  • 14,671
  • 8
  • 41
  • 63
gullamahi
  • 107
  • 2
  • 11

1 Answers1

0

You need to use the contentWindow property like so:

navFrame = window.parent.frames[0];
lnkTags = navFrame.contentWindow.document.getElementsByTagName('a');
haim770
  • 45,540
  • 6
  • 91
  • 121
  • I get the following error if I use contentWindow property: navFrame = window.parent.frames[0].contentWindow; Unsafe JavaScript attempt to access frame with URL file:///C:/Program%20Files/HNet/Publications/Title.htm# from frame with URL file:///C:/Program%20Files/HNet/Publications/Hyper.Net_Features_-_doc_d4779823/topics/4.1_Fonts/breadcrumb.htm. Domains, protocols and ports must match. – gullamahi May 13 '13 at 07:43
  • That's another problem. please read about `cross domain scripting`. in your case you can solve this easily by running your website from `localhost` instead of `file://...` – haim770 May 13 '13 at 07:48
  • Thank you for your comment. I need to have it working both from local computer and localhost. It is working from localhost but not from local computer. I have always contentWindow is undefined for the Iframe in Chrome. Is there any specific properties for chrome to get the document object of Iframe. – gullamahi May 13 '13 at 08:02
  • See here: https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file:_URIs and also http://stackoverflow.com/questions/1289063/how-to-bypass-document-domain-limitations-when-opening-local-files – haim770 May 13 '13 at 08:12
  • For Google Chrome: http://stackoverflow.com/questions/3102819/chrome-disable-same-origin-policy – haim770 May 13 '13 at 08:13