Skip to content

Instantly share code, notes, and snippets.

@gdakram
Created January 14, 2011 22:06
Show Gist options
  • Save gdakram/780360 to your computer and use it in GitHub Desktop.
Save gdakram/780360 to your computer and use it in GitHub Desktop.
challenge
<a href="#" class="save_to_academia_bookmarks">Save to Academia Bookmarks</a>
<script type="text/javascript">
window.Academia = window.Academia || {};
(function(a){
// the load event handler for the iframe
a.iframe_loaded = function(e) { console.log(e); }
// the click event handler for
a.a_links = document.getElementsByClassName("save_to_academia_bookmarks");
for (i = 0; i < a.a_links.length; i++) {
a.a_links[i].onclick = function(e){
// remove old occurrences of iframe
try{ document.body.removeChild(document.getElementById("academia_iframe")); }catch(x){}
// create the iframe
a.iframe = document.createElement("iframe");
a.iframe.id = "academia_iframe";
a.iframe.style.display = "none";
document.body.appendChild(a.iframe);
a.iframe.addEventListener("load", function(e){ a.iframe_loaded(e) }, true);
// create the form
var iframe_doc = a.iframe.contentWindow.document;
iframe_doc.open();
iframe_doc.write('<form method="POST" action="http://bookmarking-application.com/bookmarks">');
iframe_doc.write('<input type="hidden" name="url" value="'+window.location.href+'">');
iframe_doc.write('</form>');
iframe_doc.close();
a.iframe.contentWindow.document.forms[0].submit();
return false;
}
}
})(Academia);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment