Skip to content

Instantly share code, notes, and snippets.

@colinyoung
Forked from jrbruce/js_code.js
Created February 15, 2011 19:26
Show Gist options
  • Save colinyoung/828064 to your computer and use it in GitHub Desktop.
Save colinyoung/828064 to your computer and use it in GitHub Desktop.
// Need to grab hash from page here
// Append hash to iFrame src url
var hash = (location.href.split("#")[1] || "");
// change to your application's requirement, probably hash or id
var your_param = "hash_value";
// Set path to the iframe file
var url = 'http://www.google.com/';
if (hash) url += '?' + your_param + '=' + hash;
// Setup the iframe target
var iframe='<iframe id="frame" name="widget" src ="#" width="100%" height="1" marginheight="0" marginwidth="0" frameborder="no" scrolling="no"></iframe>';
// Write the iframe to the page
document.write(iframe);
var myIframe = parent.document.getElementById("frame");
// Setup the width and height
myIframe.height = 350;
myIframe.width = 960;
myIframe.src = url;
// set the style of the iframe
myIframe.style.border = "1px solid #999";
myIframe.style.padding = "8px";
<html>
<head><title>Awesome Test</title></head>
<body>
<!-- one line of JavaScript is all that is needed to generate the iframe. -->
<script language="JavaScript" src="js_code.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment