Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created November 18, 2011 01:51
Show Gist options
  • Save alejandrolechuga/1375303 to your computer and use it in GitHub Desktop.
Save alejandrolechuga/1375303 to your computer and use it in GitHub Desktop.
embeding external script cross-subdomain
<!--file content site B-->
<h1>Red Dot Avatar</h1>
<br>
<img src="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP
C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA
AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J
REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="red dot">
<!DOCTYPE >
<html>
<head></head>
<body>
<script type="text/javascript" src="http://deca.ramonlechuga.com/testB/script.js"></script>
<script type="text/javascript">
iframeCall("http://deca.ramonlechuga.com/testB/content.html");
</script>
</body>
</html>
<!DOCTYPE >
<!--iframe to call site B-->
<html>
<head></head>
<body>
<script type="text/javascript">
(function(){
document.domain = "ramonlechuga.com";
var request = new XMLHttpRequest();
var hash = location.hash.split("#contentURL:");
if (hash[1]) {
request.open('GET', decodeURI(hash[1]), false);
request.send(null);
if (request.status == 200) {
//console.log(request.responseText);
parent.embedString(request.responseText);
}
}
return;
})();
</script>
</body>
</html>
/**
script to embed site A or B
*/
var iframeCall = function (url){
document.domain = "ramonlechuga.com";
var
pub = {},
iframeHTML = document.createElement("iframe"),
iframeURL = "http://deca.ramonlechuga.com/testB/iframe.html",
URL = "",
content = false,
interval = false,
intervalTime= 10;
//url for the content
iframeURL += "#contentURL:" + encodeURI(url);
//Function to embed
window.embedString = function(string) {
iframeHTML.parentNode.removeChild(iframeHTML);
content = string;
};
//Interval to cheat the document.write
interval = setInterval(function(){
if (content) {
clearInterval(interval);
document.write(content);
}
},intervalTime);
iframeHTML.src = iframeURL;
iframeHTML.style.display ="none";
document.body.appendChild(iframeHTML);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment