Edu Edu - 1 year ago 90
Javascript Question

Get element with jquery using iframe window

Im using Liferay.Utils.Window to open a window (A), inside that window i open another window(B), when i close the window(B) i want to reload the parent window(A). I cant get to use Liferay.Portlet.refresh("p_p_id_IdPortlet") as it doesnt work...ok, no problem,i reloaded the iframe like this:

$('#' + windowId).find('iframe').attr( 'src', function ( i, val ) { return val; });

Here is where my problem appears, when i try to run that code on the Chrome console i get
"VM10008:1 Uncaught TypeError: Cannot read property 'find' of null(…)"

And the weird thing (really weird) is that if i inspect the elements of html, changing the tab inside chrome elements, i go back to console and i run the same code again and it works...weirdest thing ever. I think that when i inspect some element of the dom something is loaded, something that allows me to find the element im searching for. Any help is appreciated.


EDIT: I leave an example to understand: On Chrome console i write

<iframe class=​"dialog-iframe-node " frameborder=​"0" id=​"newAssignmentRoleDialogId_iframe_" name=​"newAssignmentRoleDialogId_iframe_" src=​"http:​/​/​localhost:​8080/​group/​catalogo-de-datos/​manage-people?p_p_auth…e&_assignmentroletoperson_WAR_abecebcatalogportlet_personFirstName=Eduardo" style=​"height:​ 485px;​ width:​ 1218px;​">​#document</iframe>​

As seen i search the element by class and it founds it, but it wont find it by id after it told me the element exists

Edu Edu
Answer Source

your solution didnt work for me, finally i found a way. I used: document.location.href=parentURL; where parentURL was passed by parameter, so that did reload the iframe. Thanks for your time

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download