How to send a message in iBram

I am looking for a postMessage method for sibling iFrame without javascript on the parent page. The difficulty I am facing is trying to get the window object for another iFrame from the first iFrame

The page will be laid out like this:

html body (http://host.com/)
  iFrame#a (http://me.com/a)
  iFrame#b (http://me.com/b)

From iFrame#aI'm trying to do:

(iFrame#b window).postMessage(...)

The problem is that I do not know how to get the window object for iFrame#bfrom iFrame#a. parent.getElementById()and other functions subject to XSS restrictions. I just want to highlight postMessagefor all other iFrames on the parent page from my domain http://me.com/in the above example.

+2
source share
2 answers

, /iframe, , /iframe iframe /iframe. - window.top.frames ( ) window.parent.frames ( , ). getElementById , DOM. . : https://developer.mozilla.org/en-US/docs/DOM/window.frames

window.frames , , postMessage iframe. , , postMessage. postMessage iframe , :

var frames = window.parent.frames;
for (var i = 0; i < frames.length; i++) { 
  frames[i].postMessage("hello", targetDomain);
}
+6

, iframe , ( ), ( ). , XSS, , .

:

+3

Source: https://habr.com/ru/post/1618995/


All Articles