Talking to other frames in Javascript

Want to talk between iframes?
Tested in Safari 8.0.2 (10600.2.5), Firefox 35.0 and Chrome 40.0.2214.91 (64-bit) on MacOS

Communication between a parent and a child frame

Parent: “Hi there kiddo, was your content by any chance changed?”
Child : ‘Yes it was father!’
Parent: “Okay, let’s not close this tab then, but instead show your regular change reminder!”

OR

Parent: “Hi there kiddo, was your content by any chance changed?”
Child : ‘No it was not.’
Parent: “Okay, let’s close this tab then!”

Actual code

Parent:

/**
* Remove a tab and tab-content
*/
function closeTab(tabId){
	var test = document.getElementById('content_'+tabId).contentWindow.hasWeekscheduleChangedIframe();
		
	// If the test was true, something changed in child, escape from function
	// otherwise just continue and close the tab
	if(true === test){
		return;
	}

.. 
actually close tab.
}

Child:

// Communication with parent page
function hasWeekscheduleChangedIframe(){
	if(weekschedule_changed){
		// View popup with options to discard changes, save changes or continue without action
		$('#changedWeekschedulePopup').modal({backdrop: 'static'});
		window.parent.parent.scrollTo(0, scrollTopLocation);
		return true;
	}
	return false;
}

Conclusion

In other words, to call a function within a child iframe, use the following code:

document.getElementById('elementId').contentWindow.customfunction();

Of course assuming that elementId is the id of an iframe.

Courtesy of this StackOverflow thread.