HTML and CSS Reference
In-Depth Information
function openBrowser(href) {
try {;
} catch (e) {
} finally {
window.setTimeout('location.href="' + href + '"', 150);
function handleErrorEvent (message, action){
var msg = "MRAID ERROR ";
if (action != null) {
msg += "caused by action '" + action + "', ";
msg += "Message: " + message;
window.addEventListener("DOMContentLoaded", function() {
try {
var head = document.getElementsByTagName('head')[0];
var js = document.createElement('Script');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', 'mraid.js');
} catch (e) {
console.log("Error injecting mraid.js");
console.log('DOM Loaded');
The code outlines how to interface with the MRAID API in the most simplistic of senses. The first thing you need
to do as an ad developer is to signify that you are an MRAID ad by adding the mraid.js script to your ad tag. You do
this by listening for the DOMContentLoaded event because this will fire before your DOM load event. It's crucial that
you present this information to the SDK as soon as you are able because this is the sole signifier that you are working
with an MRAID ad. If you don't have the ability to listen and handle for the DOM events, your ad script tag should
include the mraid.js file as the first script tag within its markup by writing <script defer src='mraid.js'> .
DomContentLoaded is supported in Chrome, Firefox, opera, Safari, and Ie9+. If you're targeting Ie8, be sure to
use onload or DOM ready if using jQuery.
Back to the code: next you listen for the MRAID ready event by adding an event listener in the method
checkMRAID(); . Sometimes the event fires before you can call your listener to handle it, so in that case, you can just
assume MRAID is present and loaded and can safely call init(); . Inside of init you remove the event listener,
Search WWH ::

Custom Search