Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying multiple targetOrigin uris in postmessage

Window.postMessage() has a targetOrigin parameter that can be set to a URI (to ensure the message reaches only a specific url). It can also be set to * of course (not recommended), but is there a way to specify multiple URIs as allowed?

At present I'm simply firing off one postMessage() call for each domain, but this seems a bit hacky to say the least.

like image 924
Michael Berry Avatar asked Mar 11 '16 12:03

Michael Berry


2 Answers

Unfortunately you can't. You should either provide "*" or single specified domain.

like image 100
Kamil Avatar answered Nov 19 '22 07:11

Kamil


You could try to send multiples time, one per domain:

targetWindow.postMessage(message, "https://domain1.com");
targetWindow.postMessage(message, "http://localhost");

⚠ It is not recommended use "*" to prevent security vulnerabilities.

You can also make an array + loop

like image 27
Juanmabs22 Avatar answered Nov 19 '22 07:11

Juanmabs22