I need to run JavaScript inside iFrame, I understand that I must use post message to do this but I do not understand how to use it.
Site 1 is http://www.example.com/chat.html
Site 2 (iFrame on Site 1) is http://www.example.com:7778
Site
$( "#link" ).click(function() {
document.getElementById('iframe_id_here').contentWindow.postMessage({command: 'joinChannel', args: {channel: $(this).attr('data-room')}}, '*');
});
iFrame
function joinChannel(event)
{
if (event.origin !== "http://example.com/chat.html")
return;
network.join(***How do I access $(this).attr('data-room')?***, '');
}
window.addEventListener("message", joinChannel, false);