Skip to content

Instantly share code, notes, and snippets.

@jacobsimeon
Created April 18, 2012 20:28
Show Gist options
  • Save jacobsimeon/2416333 to your computer and use it in GitHub Desktop.
Save jacobsimeon/2416333 to your computer and use it in GitHub Desktop.
Send a request to a remote server and show the response in a modal dialog.
var shorten = function(){
var frame = document.createElement('iframe');
var body = document.body;
var location = document.location;
var url = "";
if (!body) {
document.alert("Unable to shorten the url, try again after the page finishes loading");
return;
}
try {
url = "http://localhost:4567?url=";
url += encodeURIComponent(location.href);
frame.setAttribute('src',url);
frame.style.position = "fixed";
frame.style.top = "0px";
frame.style.left = "0px";
frame.style.right = "0px";
frame.style.left = "0px";
frame.style.background = "transparent";
frame.style.border = "none";
frame.style['z-index'] = "2147483647";
frame.setAttribute('name','gurl');
body.appendChild(frame);
} catch(e) {
document.alert('There was an error while processing the request to shorten that url.');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment