Last active
December 10, 2015 14:39
-
-
Save tim-peterson/4449105 to your computer and use it in GitHub Desktop.
Using Crocodoc docViewer with AJAX vs. full-page load
This file contains 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
<!--AJAX: this HTML generates a crocodoc if it is accessed via an AJAX request on another page----------------------> | |
<!--jQuery--> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script> | |
<!--docviewer.js--> | |
<script src="//static-v2.crocodoc.com/core/docviewer.js"></script> | |
<!--div for viewer--> | |
<div id="DocViewer"></div> | |
<script> | |
$.ajax({ | |
url: "//crocodoc.com/webservice/document.js?session=XXXXXXXX-session-XXXXXXXX", | |
dataType: "script", | |
success: function(){ | |
var docViewer = new DocViewer({ id: "DocViewer", zoom: "auto", page: 1 }); | |
//OR if want to put the new DocViewer in its own external script, do this: | |
/*var script = document.createElement("script"); | |
script.type = "text/javascript"; | |
script.src = "/assets/js/myCrocodocFile.js"; // use this for linked script | |
script.text = "console.log('voila!');" // use this for inline script | |
document.body.appendChild(script);*/ | |
} //success | |
}); //$.ajax | |
</script> | |
<!--NON-AJAX: the following HTML generates a Crocodoc if requested by regular, full page load--> | |
<!--jQuery--> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script> | |
<!--docviewer.js--> | |
<script src="//static-v2.crocodoc.com/core/docviewer.js"></script> | |
<!--sets a global variable "_doc" that is needed for initialization--> | |
<script src="//crocodoc.com/webservice/document.js?session=XXXXXXXX-session-XXXXXXXX"></script> | |
<!--div for viewer--> | |
<div id="DocViewer"></div> | |
<script type="text/javascript"> | |
//creates a document viewer using the "DocViewer" div | |
var docviewer = new DocViewer({ "id": "DocViewer" }); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment