tinti
tinti

Reputation: 1475

getElementById problem in Google Chrome

I have this simple line

alert(window.parent.frames[0].document.getElementById('textToSearch').value);

I have 2 frames, first with a text field with id 'textToSearch' I want to get the value of the text field in the second frame The line above is on the html file from second frame I get this error only in Google Chrome, in IE or FF works fine.

Uncaught TypeError: Cannot call method 'getElementById' of undefined

Any ideas?

Thanks in advance

Upvotes: 5

Views: 20855

Answers (2)

tinti
tinti

Reputation: 1475

Finally i figure what was the problem. I try the code from above on Google Chrome on a system local file. Due the security settings of Google Chrome this usecase is impossible. If i move all files on a web server this will work as a charm Thanks all for your support, this thread can be closed now

Upvotes: 4

Andy E
Andy E

Reputation: 344567

Use contentWindow.document instead of document:

var frame = window.parent.frames[0].contentWindow;
alert(frame.document.getElementById('textToSearch').value);

You can also just use contentDocument for most browsers, but not Internet Explorer 7 or older.

Upvotes: 3

Related Questions