Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
function inIframe() {
try {
return (window.self !== window.top) ? 1 : 0;
}
catch (e) {
return 1;
}
}
function ReopenUrlBuilder(baseUrl) {
this.baseUrl = baseUrl;
/**
* Get value of content attribute of meta tag with name attribute = name
* Fallback to top if possible
*
* @return string
*/
this._getMetaContent = function (name) {
try {
var meta = window.top.document.getElementsByTagName('meta');
for (var i = 0; i < meta.length; i++) {
if (meta[i].hasAttribute('name') && meta[i].getAttribute('name').toLowerCase() === name) {
var info = meta[i].getAttribute('content');
return this._getSafeSizeSubString(info);
}
}
}
catch (e) {
}
return '';
};
this._getWidth = function () {
return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
};
this._getHeight = function () {
return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
};
this._getSafeSizeSubString = function (str) {
var indexToCut = Math.max(str.indexOf(' ', 256), str.indexOf(',', 256));
if (indexToCut > 384 || indexToCut < 20) {
indexToCut = 256;
}
return str.substring(0, indexToCut);
};
this._getTitle = function () {
var title = document.title;
if (inIframe()) {
try {
title = window.top.document.title;
}
catch (e) {
title = '';
}
}
return this._getSafeSizeSubString(title);
};
this._getReferrer = function () {
var referrer = document.referrer;
return this._getSafeSizeSubString(referrer);
};
this.build = function () {
return this.baseUrl
+ '&cbrandom=' + Math.random()
+ '&cbtitle=' + encodeURIComponent(this._getTitle())
+ '&cbiframe=' + inIframe()
+ '&cbWidth=' + this._getWidth()
+ '&cbHeight=' + this._getHeight()
+ '&cbdescription=' + encodeURIComponent(this._getMetaContent('description'))
+ '&cbkeywords=' + encodeURIComponent(this._getMetaContent('keywords'))
+ '&cbref=' + encodeURIComponent(this._getReferrer());
};
}
/**
* Detect the browser
*
* Parse the passed user agent if possible so we can descide what we are going to do.
*
* @return Object The browser that has been detected.
*/
var browser = (function (n) {
// var n = 'Dalvik/1.6.0 (Linux; U; Android 4.3; GT-I9300 Build/JSS15J)'.toLowerCase();
n = n.replace('OPR', 'opera').toLowerCase();
var b = {
webkit: /webkit/.test(n),
chrome: /chrome|crios/.test(n),
safari: (/safari/.test(n) && !(/chrome/.test(n)) && !(/opios/.test(n))),
mozilla: (/mozilla/.test(n)) && (!/(compatible|webkit)/.test(n)),
firefox: /firefox/.test(n),
msie: ((/msie/i.test(n)) || /Trident/i.test(n)) && (!/opera/i.test(n)),
msedge: (/edge/.test(n)),
ms_mobile: /iemobile/.test(n),
opera: /opera/.test(n),
// opios is Opera Mini in iOS
opera_mini: (/opera mini/.test(n) || /opios/.test(n)),
android: /android/.test(n),
mac: /macintosh/.test(n),
blackberry: /blackberry/.test(n),
ios: /ipad|ipod|iphone/.test(n),
// FaceBook userAgent
fb: /fban\/fbios|fbav|fbios|fb_iab\/fb4a/.test(n),
presto: /presto/.test(n),
ieQuirksMode: (typeof document.compatMode !== 'undefined') ? document.compatMode !== 'CSS1Compat' && (/msie/.test(n)) && (!/opera/.test(n)) : false,
ucbrowser: /UCBrowser|UCWEB/.test(n)
};
b.user_agent = n;
// Check for the flash support
b.flash_support = false;
try {
b.flash_support = navigator.mimeTypes['application/x-shockwave-flash'];
}
catch (e) {
}
// Get the browser version
b.version = (b.safari) ? (n.match(/.+(?:ri)[\/: ]([\d.]+)/) || [])[1] : (n.match(/.+(?:ox|me|ra|ie)[\/: ]([\d.]+)/) || [])[1];
b.touchable = 'ontouchstart' in document.documentElement;
// Get the major browser version, like Chrome 41 or Firefox 38, from the full version
b.major_version = parseInt(b.version);
/* Detect if the current browser is a mobile browser or not. */
b.is_mobile = b.android || b.ios || b.blackberry || b.ms_mobile || b.opera_mini || b.ucbrowser;
return b;
})(navigator.userAgent);
var builder = new ReopenUrlBuilder("http:\/\/www.adnetworkperformance.com\/a\/display.php?r=1610711&treqn=788314452&runauction=1&crr=6cd3d4246d255c24d1da,cGQ0MCab109fe5a9b1b64bf9360&rtid=594d42f8d7f2a");
var url = builder.build();
document.write('<iframe width="100%" height="100%" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" allowfullscreen="true" style="border: medium none; padding: 0; margin: 0;" id="594d42f8d7f2a" frameborder="0" src="'+ url +'" scrolling="no"></iframe>');
if ((browser.chrome && browser.major_version < 17) || browser.opera_mini) {
document.getElementById('594d42f8d7f2a').removeAttribute('sandbox');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.