I have a parent HTML window and a pop up window. I want to access fields in parent window when I click a button inside popup.
I have tried this but it doesn't work from popup:
top.document.getElementById('itemCounter').innerHTML = '1';
It throws the following exception:
I am opening popup using window.open.
Does anyone know how to access field in parent window from pop?
The top and parent will only work with IFRAME popups. If you open a whole new window with window.open(), you'll need to use opener to access the page which opened your popup. So, try:
opener.document.getElementById('itemCounter').innerHTML = '1';
You should be able to access the parent of the pop-up window by using the following code - this.parent. This should return you the window object of the parent. You can use that object further for more manipulations.
You should try:
Use something like window.opener.document.getElementById('id'). I use it sometimes to see if it is the correct parent.
Try to use the document.getElementById() from the Opener object rather than top object.
popupWinOpener.document.getElementById('itemCounter').innerHTML = '1';
My issue is resolved. I used -
window.opener.top.document.getElementById('id').innerHTML = '1';
I wanted to access object in iFrame in parent window. Thanks all