Javascript selector to select field in parent window from popup window

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:

Javascript selector - `top.document.getElementById('itemCounter')` returns null from popup screen but return object `top.document.getElementById('itemCounter')` from parent screen.

I am opening popup using

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, 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 -'id').innerHTML = '1';

I wanted to access object in iFrame in parent window. Thanks all

Need Your Help

jquery .change function on ie

jquery internet-explorer

I have a problem binding to the change event in Internet Explorer.

Use default scope ordering with a model::findAllBySql() call


I have defaultScope() defined in my model class X to