JavaScript embed contentWindow -


I'm trying to do a JavaScript postMessage , such as you do for an iframe Now, an embed I have to use an embed as it is for an app that is loaded on iOS device, and when there is a bug with IFrame width and height in iOS then I have to use an embed .

It is loading and embedding I can post messages to parents, but in some way I can not post in embeds. Did I try:

  document.getElementById ("embed") contentWindow.postMessage (...) document.getElementById ("embed"). ContentDocument.postMessage (...) GetElementById ("Embed") document. Document. PostMessage (...) document.getElementById ("Embed"). GetSVGDocument () / / empty return   

current embed setup:

  & lt; Embed src = "URL" id = "embed" type = "text / html" & gt; & Lt; / Embed & gt;   

Any solutions for this?

If you want to get an element by ID in JS, you have to enter an ID in your element So that the JS script can find it:

  & lt; embed id = "embed" src = "URL" type = "text / html" & gt; & Lt; / Embed & gt;   

If you do not want to use the ID, you can use the GetElementsByTagName function to retrieve your element, such as:

  // If you are only an element of that type of document. GetElementsByTagName ("Embed") [0] .doSomething (); // If you have many embedded elements, embed embed = document. GetElementsByTagName ("embed"); (Var i = 0; i & lt; embeds.lenght; i ++) {document.getElementsByTagName ("embed") [i] .doSomething (); }   

Wondo property about content, it seems that it is only an IFrame property. So you have to use another property or switch back to iframe. More here:



Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -