frec
Вот код экзоклика, думаю разберетесь
var _top = null;
function getPuId() {
return "ad_" + Math.floor(89999999 * Math.random() + 10000000)
}
function addEvent(obj, type, fn) {
if (obj.addEventListener) {
obj.addEventListener(type, fn, false)
} else if (obj.attachEvent) {
obj["e" + type + fn] = fn;
obj[type + fn] = function () {
obj["e" + type + fn](window.event)
};
obj.attachEvent("on" + type, obj[type + fn])
} else {
obj["on" + type] = obj["e" + type + fn]
}
}
Date.prototype.addHours = function (h) {
this.setHours(this.getHours() + h);
return this
};
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.addHours(12);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()) + "; domain=" + baseDomain + "; path=/";
document.cookie = c_name + "=" + c_value
}
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y)
}
}
}
var exopop = {
settings: {
width: 1024,
height: 768
},
init: function () {
var browser = exopop.browser;
_top = self;
if (top != self) {
try {
if (top.document.location.toString()) {
_top = top
}
} catch (err) {}
}
if (browser.isMobile.any(_top)) {
console.log('mobile');
exopop.binders.mobile();
return
}
if (browser.is.msie) {
exopop.binders.firefox();
return
}
if (browser.is.firefox) {
exopop.binders.firefox();
return
}
if (browser.is.chrome && browser.versionFrom(33) && navigator.appVersion.indexOf("Mac") != -1) {
exopop.binders.chrome31();
return
}
if (browser.is.chrome && browser.versionFrom(30) && navigator.appVersion.indexOf("Mac") != -1) {
exopop.binders.chrome30_mac();
return
}
if (browser.is.chrome && browser.versionOlderThan(30)) {
exopop.binders.chromeUntil30();
return
}
if (browser.is.chrome && browser.versionIs(30)) {
exopop.binders.chrome30();
return
}
if (browser.is.chrome && browser.versionFrom(31)) {
exopop.binders.chrome31();
return
}
if (browser.is.safari) {
exopop.binders.safari();
return
}
exopop.binders.firefox();
return
},
windowParams: function () {
return 'width=' + exopop.settings.width + ',height=' + exopop.settings.height + ',top=0,left=0,scrollbars=1,location=1,toolbar=0,menubar=0,resizable=1,statusbar=1'
},
status: {
opened: false
},
opened: function () {
if (exopop.status.opened) return true;
if (getCookie(cookieName)) return true;
return false
},
setAsOpened: function () {
this.status.opened = true;
setCookie(cookieName, 1, 1)
},
findParentLink: function (clickedElement) {
var currentElement = clickedElement;
if (currentElement.getAttribute("target") == null && currentElement.nodeName.toLowerCase() != "html") {
var o = 0;
while (currentElement.parentNode && o <= 4 && currentElement.nodeName.toLowerCase() != "html") {
o++;
currentElement = currentElement.parentNode;
if (currentElement.nodeName.toLowerCase() === "a" && currentElement.href != "") {
break
}
}
}
return currentElement
},
triggers: {
firefox: function () {
if (exopop.opened()) return true;
var popURL = "about:blank";
var params = exopop.windowParams();
var PopWin = _top.window.open(popURL, getPuId(), params);
if (PopWin) {
PopWin.blur();
if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1) {
_top.window.blur();
_top.window.focus()
}
PopWin.Init = function (e) {
with(e) {
Params = e.Params;
Main = function () {
var x, popURL = Params.PopURL;
if (typeof window.mozPaintCount != "undefined") {
x = window.open("about:blank");
x.close()
} else if (navigator.userAgent.toLowerCase().indexOf("chrome/2") > -1) {
x = window.open("about:blank");
x.close()
}
try {
opener.window.focus()
} catch (err) {}
window.location = popURL;
window.blur()
};
Main()
}
};
PopWin.Params = {
PopURL: exoUrl
};
PopWin.Init(PopWin)
}
exopop.setAsOpened();
return
},
chromeUntil30: function () {
if (exopop.opened()) return true;
window.open('javascript:window.focus()', '_self');
var w = window.open('about:blank', getPuId(), exopop.windowParams());
var a = document.createElement('a');
a.setAttribute('href', 'data:text/html,<scr' + 'ipt>window.close();</scr' + 'ipt>');
a.style.display = 'none';
document.body.appendChild(a);
var e = document.createEvent('MouseEvents');
e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
a.dispatchEvent(e);
document.body.removeChild(a);
w.document.open().write('<script type="text/javascript">window.location="' + exoUrl + '";<\/script>');
w.document.close();
exopop.setAsOpened()
},
chrome30: function (W) {
if (exopop.opened()) return true;
var link = document.createElement("a");
link.href = 'javascript:window.open("' + exoUrl + '","' + getPuId() + '","' + exopop.windowParams() + '")';
document.body.appendChild(link);
link.webkitRequestFullscreen();
var event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);
link.dispatchEvent(event);
document.webkitCancelFullScreen();
setTimeout(function () {
window.getSelection().empty()
}, 250);
var Z = W.target || W.srcElement;
Z.click();
exopop.setAsOpened()
},
safari: function () {
if (exopop.opened()) return true;
var popWindow = _top.window.open(exoUrl, getPuId(), exopop.windowParams());
if (popWindow) {
popWindow.blur();
popWindow.opener.window.focus();
window.self.window.focus();
window.focus();
var P = "";
var O = top.window.document.createElement("a");
O.href = "data:text/html,<scr" + P + "ipt>window.close();</scr" + P + "ipt>";
document.getElementsByTagName("body")[0].appendChild(O);
var N = top.window.document.createEvent("MouseEvents");
N.initMouseEvent("click", false, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
O.dispatchEvent(N);
O.parentNode.removeChild(O)
}
exopop.setAsOpened()
},
tab: function () {
if (exopop.opened()) return true;
var u = (!exoUrl) ? 'data:text/html,<script>window.close();</script>;' : exoUrl;
var a = top.window.document.createElement("a");
var e = document.createEvent("MouseEvents");
a.href = u;
document.getElementsByTagName("body")[0].appendChild(a);
e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
a.dispatchEvent(e);
a.parentNode.removeChild(a);
exopop.setAsOpened()
},
mobile: function (triggeredEvent) {
if (exopop.opened()) return true;
var clickedElement = triggeredEvent.target || triggeredEvent.srcElement;
if (clickedElement.nodeName.toLowerCase() !== "a") {
clickedElement = exopop.findParentLink(clickedElement)
}
if (clickedElement.nodeName.toLowerCase() === "a" && clickedElement.getAttribute("target") !== "_blank") {
window.open(clickedElement.getAttribute("href"));
exopop.setAsOpened();
_top.document.location = exoUrl;
if (triggeredEvent.preventDefault != undefined) {
triggeredEvent.preventDefault();
triggeredEvent.stopPropagation()
}
return false
}
return true
}
},
binders: {
explorer: function () {
addEvent(document, 'click', exopop.triggers.firefox)
},
firefox: function () {
addEvent(document, 'click', exopop.triggers.firefox)
},
chromeUntil30: function () {
addEvent(document, 'mousedown', exopop.triggers.chromeUntil30)
},
chrome30: function () {
addEvent(document, 'mousedown', exopop.triggers.chrome30)
},
chrome31: function () {
addEvent(document, 'mousedown', exopop.triggers.tab)
},
chrome30_mac: function () {
addEvent(document, 'mousedown', exopop.triggers.chromeUntil30)
},
safari: function () {
addEvent(document, 'mousedown', exopop.triggers.safari)
},
mobile: function () {
addEvent(document, 'click', exopop.triggers.mobile)
}
},
browser: {
is: function () {
var userAgent = navigator.userAgent.toLowerCase();
var info = {
webkit: /webkit/.test(userAgent),
mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent)),
chrome: /chrome/.test(userAgent),
msie: ((/msie/.test(userAgent)) && (!/opera/.test(userAgent)) || (!!navigator.userAgent.match(/Trident.*rv/))),
firefox: /firefox/.test(userAgent),
safari: (/safari/.test(userAgent) && !(/chrome/.test(userAgent))),
opera: /opera/.test(userAgent),
ie: (!!navigator.userAgent.match(/Trident.*rv/))
};
if (info.safari) {
info.version = (userAgent.match(/.+(?:ri)[\/: ]([\d.]+)/) || [])[1]
} else if (info.ie) {
var re = new RegExp("trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
info.version = (re.exec(userAgent) != null) ? parseFloat(RegExp.$1) : null
} else {
info.version = (userAgent.match(/.+(?
x|me|ra|ie)[\/: ]([\d.]+)/) || [])[1]
}
return info
}(),
versionNewerThan: function (version) {
currentVersion = parseInt(this.is.version.split('.')[0]);
return currentVersion > version
},
versionFrom: function (version) {
currentVersion = parseInt(this.is.version.split('.')[0]);
return currentVersion >= version
},
versionOlderThan: function (version) {
currentVersion = parseInt(this.is.version.split('.')[0]);
return currentVersion < version
},
versionIs: function (version) {
currentVersion = parseInt(this.is.version.split('.')[0]);
return currentVersion == version
},
isMobile: {
Android: function (a) {
return a.navigator.userAgent.match(/Android/i)
},
BlackBerry: function (a) {
return a.navigator.userAgent.match(/BlackBerry/i)
},
iOS: function (a) {
return a.navigator.userAgent.match(/iPhone|iPad|iPod/i)
},
Opera: function (a) {
return a.navigator.userAgent.match(/Opera Mini/i)
},
Windows: function (a) {
return a.navigator.userAgent.match(/IEMobile/i)
},
any: function (a) {
return a.navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)
}
}
}
};
exopop.init();
frec
Вот еще один код с открыванием скрытых вкладок, думаю тоже разберетесь
var MTid = "9353098050";
function MTdef(variable) {
return (typeof (variable) == "undefined") ? false : true;
}
var MTua = navigator.userAgent.toLowerCase();
var MTf = -1 != MTua.indexOf("opera");
var MTg = -1 != MTua.indexOf("chrome");
var MTdl = "24";
var MTbl = "";
var MTwl = "";
var MTmw = 450;
var MTurl = "http://ya.ru";
var MTcl = [1].sort();
var MTcc = 0;
var MTslT = false;
var MTac;
MTbl = MTbl=="" ? [] : MTbl.split(" ");
MTwl = MTwl=="" ? [] : MTwl.split(" ");
function chPrnt(el, lt) {
var r = false;
if (el!=null) {
l = lt=="w" ? MTwl : MTbl;
if (l.length>0) {
for (var i=0; i<l.length;i++) if (el.id == MTbl[i]) {
r = true ;
break;
}
delete l;!r && (r = chPrnt(el.parentNode, lt));
}
}
return r;
}
function MTaddL(elem) {
elem.addEventListener ? elem.addEventListener("mouseup", openNewTab, !1) : elem.attachEvent("onmouseup", openNewTab);
}
function MTnCL () {
return (MTcl.length>0) ? MTcl.shift() : false;
}
function setV(a, b) {
var c = MTdl, d = new Date;
d.setTime(d.getTime());
document.cookie = a + "=" + escape(b) + ";expires=" + (new Date(d.getTime() + c * 36E5)).toGMTString() + ";path=/;";
}
function getV(a) {
var b = document.cookie;
a += "=";
var c = b.indexOf("; " + a);
if (-1 == c) {
if (c = b.indexOf(a), 0 != c) return null;
} else c += 2;
var d = document.cookie.indexOf(";", c);- 1 == d && (d = b.length);
return unescape(b.substring(c + a.length, d));
}
function openNewTab() {
var a = getV("MT_CL" + MTid) ? parseInt(getV("MT_CL" + MTid)) : MTcc;
a++;
MTac!==false && (setV("MT_CL" + MTid, a));
if (!getV("MT_ID" + MTid + "." + MTac) && a==MTac) {
setV("MT_ID" + MTid + "." + MTac, 1);
if (document.createEvent && (MTf || MTg)) {
var b = document.createElement("a");
b.href = MTurl;
b.target = "_blank";
var c = document.createEvent("MouseEvents");
c.initMouseEvent("click", !0, !0, window, 1, 0, 0, 0, 0, !0, !1, !1, !1, 1, null);
b.dispatchEvent(c);
} else {
b = window.open("about:blank", "win" + Math.floor(9999999 * Math.random()) + 1, "toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,top=0,left=0,width=" + window.screen.width + "px,height=" + window.screen.height + "px");
with(b) opener.window.focus(), b.location = MTurl, "undefined" != typeof window.mozPaintCount && window.open("about:blank").close();
}
for (var b = document.getElementsByClassName("mtaddiv"), c = b.length, d = 0;d < c; d++) "object" == typeof b[d] && b[d].setAttribute("style", "position:none;left:0px;top:0px;height:0;width:0;z-index:0;display:none;");
MTac = MTnCL();
}
a == MTac-1 &&( add_mtaddiv("iframe"), add_mtaddiv("object"), add_mtaddiv("embed"));
MTcc = a;
}
function add_mtaddiv(a) {
try {
if (!getV("MT_ID" + MTid + "." + MTac)) {
var b = document.getElementsByTagName(a), c = b.length;
for (a = 0; a < c; a++) {
var d = b[a].offsetWidth, B = b[a].offsetHeight, en=1;
if (MTwl.length>0 && !chPrnt(b[a],"w")) en = 0;
if( en==1 && (MTbl.length>0 && chPrnt(b[a],"b"))) en = 0;
if (d > MTmw && en==1) {
mtaddiv = document.createElement("div");
mtaddiv.className = "mtaddiv";
var n, u = b[a].getBoundingClientRect(), l = document.body, m = document.documentElement;
n = {top: Math.round(u.top + (window.pageYOffset || (m.scrollTop || l.scrollTop)) - (m.clientTop || (l.clientTop || 0))), left: Math.round(u.left + (window.pageXOffset || (m.scrollLeft || l.scrollLeft)) - (m.clientLeft || (l.clientLeft || 0)))};
mtaddiv.setAttribute("style", "position: absolute;left:" + n.left + "px;top:" + n.top + "px;height:" + B + "px;width:" + d + "px;z-index:899");
(MTwl.length > 0) && MTaddL(mtaddiv);
document.body.appendChild(mtaddiv);
}
}
}
} catch (C) {
}
}
var startTimeout = setTimeout(bcStart, 3E3), startScript = null;
if ("function" == typeof window.addEventListener) {
window.addEventListener("load", function () {clearInterval(startTimeout); bcStart();}, !1);
} else try {
window.attachEvent("onload", function () {clearInterval(startTimeout);bcStart();});
} catch (D) {
}
function bcStart() {
if (!startScript) {
startScript = !0;
MTcc = getV("MT_CL" + MTid) ? parseInt(getV("MT_CL" + MTid)) : 0;
while (MTcl.length>0) {
MTac = MTnCL();
if (MTac>MTcc) break;
}
MTcl.length==0 && MTac<=MTcc && (MTac = false);
(MTcc==MTac-1 && MTac) && (add_mtaddiv("iframe"), add_mtaddiv("object"), add_mtaddiv("embed"));
for (var a = MTbl, b = a.length, c = 0; c < b; c++) {
var d = document.getElementById(a[c]);
null != d && (d.onmouseup = function (a) {a = a || window.event;a.stopPropagation ? a.stopPropagation() : a.cancelBubble = !0;});
}
if (MTwl.length > 0) {
for (i=0;i<MTwl.length;i++) {
var el = document.getElementById(MTwl[i]);
el!=null &&MTaddL(el);
}
} else MTaddL(document);
}
}
document.getElementsByClassName = function (a) {
var b = [];
a = RegExp("\\b" + a + "\\b");
for (var c = this.getElementsByTagName("*"), d = 0;d < c.length; d++) a.test(c[d].className) && b.push(c[d]);
return b;
};