CRM has several global functions and variables that can be used in your JavaScript's to gain information about the context that CRM is currently being used in.
Pre 2016 you accessed these functions by simply calling them directly…
if (IsOnline()){ alert("You are online"); }
However in 2016 due to the use of TurboForms and the way that they load form content in a wrapper class (explained here) accessing the content of the IFrame is no longer direct you must first call on the parent.
if (parent.IsOnline()){ alert("You are online"); }
NOTE: in this example I have used the IsOnline global method however wherever possible you should use the Xrm.Page methods. In this case context.client.getClientState()
This also applies to unsupported code where you are accessing the DOM.
document.getElementById("mag_fieldname").style.backgroundColor="#abcdef"
Becomes
parent.document.getElementById("mag_fieldname").style.backgroundColor="#abcdef"
NOTE: if you disable turbo forms these script changes will break. I recommend that you put in a null check and act accordingly.
var fieldElement = document.getElementById("mag_fieldname");if (fieldElement!=null){ document.getElementById("mag_fieldname").style.backgroundColor="#abcdef" } else { parent.document.getElementById("mag_fieldname").style.backgroundColor="#abcdef" }