Skip to content

Instantly share code, notes, and snippets.

@crittermike
Last active May 23, 2017 19:10
Show Gist options
  • Save crittermike/eed2d87e836a39240af76e405432dc21 to your computer and use it in GitHub Desktop.
Save crittermike/eed2d87e836a39240af76e405432dc21 to your computer and use it in GitHub Desktop.
<div id="widget-container"></div>
<script type="text/javascript">
// First grab the `view` param from the query string, if it exists
var reg = new RegExp( '[?&]' + 'view' + '=([^&#]*)', 'i' );
var paramSearch = reg.exec(window.location.search);
var param = paramSearch ? paramSearch[1] : '';
// Then build the JS file
var js = document.createElement("script");
js.type = "text/javascript";
js.src = "//getchant.com/widget/polling.min.js";
// Then set the data-poll attribute based on the value from the query string
js.setAttribute('data-poll', param);
// Finally insert the JS file into the page.
document.getElementById("widget-container").appendChild(js);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment