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 window.open.

Does anyone know how to access field in parent window from pop?

Thanks

Answers


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:

alert(window.opener...);

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


Need Your Help

jquery .change function on ie

jquery asp.net-mvc internet-explorer

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

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

yii

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

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.