I'm trying to update the innerHTML of a div tag that's within the parent window from within an iframe. How do I access the parent window?
Use window.parent. Note, however, that you can only manipulate the parent document if it belongs to the same domain.
Related
I want to replace a HTML document in the browser with another HTML document or another DOM without changing the document.location.
Possible with JavaScript?
No you can't change a Window's document property by any other means than navigation (in case of an opened Window or an <iframe>'s one from about:blank).
https://html.spec.whatwg.org/multipage/window-object.html#concept-document-window
I have a complex code that travels inside windows and iframes (yes, windows cause I open some windows with window.open sometimes and also travel inside iframes) and when some condition apply I get an element from inside of those iframes (they usually are DIVs and SPANs).
So, I have the element that I want in the object "$(this)" so from the parent window how can I know the "document" element that has this element? I need to get the "document" element that has "$(this)" and set some attributes to it.
I tried $(this).parents(document) but it does not work.
If this refers to an element (such that $(this) would give you a jQuery wrapper around it) or indeed any Node, then this.ownerDocument is a reference to the document the element is in (null if it's not in a document). Details in ownerDocument in the specification.
I have a page with an iFrame embeded. Now I want to modify a object (for example a Button) outside this iFrame by clicking on a button inside the iFrame (with Javascript).
How does this work? Can I just do it like usual?
You can access the parent window using window.parent. From that point, you should be able to do it like usual.
Example :
$('#yourButtonId', window.parent.document).
See also how to access iFrame parent page using jquery? as the question has already been asked
I have set up a page (the parent) with an IFRAME (the child). What are the best methods for the parent to capture the click events of the child?
Addendum: Both pages are located on the same domain. jQuery is included.
If all of your client browsers are MOZ capable, you can use the HTMLIFrameElement reference which inherits all of the standard HTMLElement methods and properties.
i believe that i have to use an array but im not sure where it should be placed and how it should look. im working with javascript and am kinda new at it. should the array be in the tags? or the tag? or should it be inside of the tags but outside of the other two? im lost. should the array be written in just the parent file or the child file? or both? i have created two different pages and now i want the button on one page to return the other page and the button on the child page to close the window. which i think involves the close() option since i used the open() to bring up a new window.
It is unclear what you mean. The way one window accesses another window's properties depends on how they relate; from "child" frame to parent, from parent to "child", from "child" to "sibling"...
If you want to access another frame from within a frame, you're probably best off giving the other frame an id and using something like parent.getElementById("yourId").contentWindow. This will give you the other frame's window object, on which you can call close().
I think this link explains how to access windows, frames and parents.