Last active
August 29, 2015 14:15
-
-
Save tomhodgins/1cd7ec5b0d6300aa03e4 to your computer and use it in GitHub Desktop.
Self Executing JavaScript Widget (HTML + CSS): just place a link to this script in your HTML where you want the content to appear, like <script src="myWidget.js"></script>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var myWidget = document.createElement('section'), | |
widgetStyles = document.createElement('style'), | |
tag = document.querySelectorAll('[src*="myWidget"]')[0]; | |
myWidget.innerHTML = '\ | |
<!-- Add your HTML here, with line-breaks escaped by a "\" backslash character. -->\ | |
<!-- (Don\'t forget: you can escape any character, like quotes, as well -->\ | |
Hello\ | |
'; | |
widgetStyles.innerHTML = '\ | |
/* Add your CSS here, with line-breaks escaped by a "\" backslash character */\ | |
html { background: #09f; }\ | |
'; | |
function populateWidget(content) { | |
tag.parentNode.insertBefore(content, tag.nextSibling); | |
}; | |
populateWidget(widgetStyles); | |
populateWidget(myWidget); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment