Javascript date objects in different browsers

So we use a tool called dhtmlxscheduler for filling our timetables. It works nice! We just drag and drop the times we want and press save to edit the current weekschedule in PHP.

However..

Internet Explorer had a weird bug where it set all the times to 01:00 – 01:00.
So I started investigating why this could be, and it turned out that the time was send to PHP correctly, but PHP could not interpret the string returned from the date object of IE. The other major browsers seemed to have no issues with this whatsoever..

It turns out the date string outputted in IE was different from other browsers.

The solution was to format the date to a general string before sending it to PHP;

// Format the date to be used in a general way, IE had some issues with this, of course..
var tmpdate = null;
var tmptime = null;
var hours = null;
var minutes = null;
var seconds = null;

tmpdate = $.datepicker.formatDate('yy-mm-dd', eventdata[attribute]);
// Add leading zero's if needed
hours = eventdata[attribute].getHours(); 
if(hours < 10){ hours = "0"+hours; }

minutes = eventdata[attribute].getMinutes(); 
if(minutes < 10){ minutes = "0"+minutes; }

seconds = eventdata[attribute].getSeconds(); 
if(seconds < 10){ seconds = "0"+seconds; }

tmptime = hours+':'+minutes+':'+seconds;
$newHiddenElement.val(tmpdate +' '+ tmptime);

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.