Skip to content

Instantly share code, notes, and snippets.

@suciptoid
Created December 27, 2015 14:13
Show Gist options
  • Save suciptoid/66f29159cb8512f25eaa to your computer and use it in GitHub Desktop.
Save suciptoid/66f29159cb8512f25eaa to your computer and use it in GitHub Desktop.
ibnads.xl.co.id iframe script
//09/22/2015/22:54//iframeJs
var targetUrl = window.location.href;
if (self !== top) {
self.location.href = targetUrl
}
var iframe = iframe || {
object: null,
init: function init() {
this.object = document.getElementById("main-frame")
},
iframeHeight: 0,
resizeHeight: function() {
var a = document.getElementsByTagName('body')[0];
var b = this.object.contentWindow || this.object.contentDocument.parentWindow;
var c = b.document.documentElement.scrollHeight || b.document.body.scrollHeight;
try {
var c = b.document.body.scrollHeight > b.document.documentElement.scrollHeight ? b.document.body.scrollHeight : b.document.documentElement.scrollHeight
} catch (err) {
return true
}
if (c && c > this.iframeHeight) {
this.object.height = c;
a.height = this.object.height;
this.object.style.height = c + "px";
this.iframeHeight = c
}
},
clone: function clone(a) {
if (a == null || typeof(a) !== 'object') {
return a
}
if (typeof a.clone == 'function') {
return a.clone(true)
}
if (a instanceof Date) {
return new Date(a.getTime())
}
if (a instanceof RegExp) {
return new RegExp(a)
}
if (a.nodeType && typeof a.cloneNode == 'function') {
return a.cloneNode(true)
}
var b = (Object.getPrototypeOf ? Object.getPrototypeOf(a) : a.__proto__);
if (!b) {
b = a.constructor.prototype
}
var c = object_create(b);
for (var d in a) {
c[d] = this.clone(a[d])
}
return c
},
copiedMetaTag: {},
copyMetaTagIfExisted: function copyMetaTagIfExisted() {
try {
var a = this.object.contentWindow.document.documentElement.getElementsByTagName('meta');
var b = null;
var d = ['viewport', 'apple-mobile-web-app-capable'];
var e = document.getElementsByTagName('head')[0];
for (var f = 0; f < d.length; f++) {
var g = d[f];
for (var i in a) {
var h = a[i];
if (h.name == g && this.copiedMetaTag[g] == null) {
var c = this.clone(h);
e.appendChild(c);
this.copiedMetaTag[g] = g
}
}
}
} catch (ex) {}
},
copyTitle: function copyTitle() {
try {
var a = this.object.contentWindow.document.documentElement.getElementsByTagName('title');
if (a && a.length > 0) {
var b = document.getElementsByTagName('head')[0];
b.appendChild(a[0])
}
} catch (ex) {}
},
isHeadAlreadyExist: false,
isBodyAlreadyExist: false,
checkRedirectionAndBodyExist: function checkRedirectionAndBodyExist() {
if (iframe.isFinishLoad) {
return
}
var a = 100;
var c = null;
var d = null;
try {
if (iframe.object.contentDocument) {
c = iframe.object.contentDocument.getElementsByTagName('head')[0];
d = iframe.object.contentDocument.getElementsByTagName('body')[0]
} else if (iframe.object.contentWindow) {
c = iframe.object.contentWindow.document.getElementsByTagName('head')[0];
d = iframe.object.contentWindow.document.getElementsByTagName('body')[0]
}
} catch (b) {}
iframe.isHeadAlreadyExist = c != null && c.innerHTML.length > 0;
iframe.isBodyAlreadyExist = d != null && d.innerHTML.length > 0;
var f;
try {
f = iframe.object.contentDocument || iframe.object.contentWindow.document
} catch (e) {}
if (f) {
setTimeout(function() {
iframe.checkRedirectionAndBodyExist()
}, a)
} else {
this.redirectToOriginalPage()
}
},
isFinishLoad: false,
onload: function() {
setTimeout(function() {
iframe.isFinishLoad = true
}, 200)
},
updateHeadWhenExist: function updateHeadWhenExist() {
var a = 100;
if (iframe.isHeadAlreadyExist) {
iframe.copyMetaTagIfExisted();
iframe.copyTitle()
} else {
setTimeout(function() {
iframe.updateHeadWhenExist()
}, a)
}
},
displayWhenBodyExist: function displayWhenBodyExist() {
var a = 100;
if (iframe.isBodyAlreadyExist) {
this.object.style.display = "";
setInterval(function() {
iframe.resizeHeight();
iframe.updateAnchorTagInFrame()
}, 1000)
} else {
setTimeout(function() {
iframe.displayWhenBodyExist()
}, a)
}
},
updateAnchorTagInFrame: function updateAnchorTagInFrame() {
var b = this.object.contentWindow.document.documentElement.getElementsByTagName('a');
for (var i = 0; i < b.length; i++) {
var a = b[i];
a.setAttribute('target', '_top')
}
},
compatibilityCheck: function compatibilityCheck() {
var a = targetUrl;
if (/(firefox|IEMobile)/i.test(navigator.userAgent)) {
if (targetUrl.indexOf('?') > 0) {
a = a + "&"
} else {
this.redirectToOriginalPage();
return
}
}
return a
},
redirectToOriginalPage: function redirectToOriginalPage() {
window.location.href = targetUrl
},
loadOriginalPage: function loadOriginalPage() {
this.init();
this.object.style.display = "none";
this.object.onload = this.onload;
this.object.src = this.compatibilityCheck();
setTimeout(function() {
iframe.checkRedirectionAndBodyExist();
iframe.updateHeadWhenExist();
iframe.displayWhenBodyExist()
}, 300)
},
createIframeInBody: function createIframeInBody() {
function createElement(a, b) {
var c = document.createElement(a);
b(c);
return c
}
var e = createElement('div', function(d) {
d.id = 'container';
d.appendChild(createElement('div', function(a) {
a.id = 'top-banner'
}));
d.appendChild(createElement('div', function(c) {
c.id = 'middle';
c.appendChild(createElement('div', function(a) {
a.id = 'left-banner'
}));
c.appendChild(createElement('div', function(b) {
b.id = 'content';
b.appendChild(createElement('iframe', function(a) {
a.id = 'main-frame';
a.scrolling = 'no'
}))
}));
c.appendChild(createElement('div', function(a) {
a.id = 'right-banner'
}))
}));
d.appendChild(createElement('div', function(a) {
a.id = 'bottom-banner'
}))
});
var f = document.getElementsByTagName('body')[0];
f.insertBefore(e, f.firstChild)
},
main: function main() {
iframe.createIframeInBody();
this.loadOriginalPage()
}
};
iframe.main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment