Skip to content

Instantly share code, notes, and snippets.

@earth2marsh
Created March 7, 2011 23:59
Show Gist options
  • Save earth2marsh/859554 to your computer and use it in GitHub Desktop.
Save earth2marsh/859554 to your computer and use it in GitHub Desktop.
Example for passing a URL to an embedded Console
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<script type="text/javascript">
var addEvent = function(obj, type, fn) {
if (obj.addEventListener) {
obj.addEventListener(type, fn, false);
} else if (obj.attachEvent) {
obj.attachEvent('on' + type, function() { return fn.apply(obj, new Array(window.event));});
}
}
addEvent(window, 'load', preProcessPage);
function preProcessPage() {
if (!document.getElementsByTagName || (!document.getElementById || (!document.createElement || !document.createTextNode))) return false;
processPage();
}
function processPage() {
function parseURL() {
var tmp = window.location.href.split("?");
if (tmp[1]) {
tmp = tmp[1].split("#");
this.anchor = tmp[1];
if (tmp[0]) {
tmp = tmp[0].split("&");
if(tmp[0]) {
this.hasparams = 1;
for(var i=0; i<tmp.length; i++) {
var record = tmp[i].split("=");
if (record) {
eval("this."+record[0]+" = \'" + record[1] + "\'");
}
}
}
}
}
}
function build_console(console_url, method, request) {
if (request && method) {
console_url += "#apimet=" + urldigest.request + "__apiidx__%3Dstatuses/public_timeline__apisecure__%3Dtrue__apiprovider__%3Dtwitter__httpmet__%3D" + urldigest.method;
}
var console = document.createElement('iframe');
console.setAttribute("width", "100%");
console.setAttribute("height", "600");
console.setAttribute("src", console_url);
return console;
}
var urldigest = new parseURL();
var myconsole = build_console("https://apigee.com/embed/console/twitter", urldigest.request, urldigest.method);
document.getElementById("console_container").appendChild(myconsole);
}
</script>
</head>
<body>
<div id="header"><h1>Your header</h1></div>
<p><i>This is an example of how to pass a method and resource url into an embedded Console (<a style="text-decoration:underline;color:blue;" onclick="location.href = location.origin + location.pathname + '?method=GET&request='+'http://api.twitter.com/1/statuses/public_timeline.json';">try it now</a>).</i></p>
<div id="console_container">
</div>
<div id="footer"><p>Your footer</p></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment