Created
November 2, 2019 01:17
-
-
Save luisenriquecorona/5528c505d20379070d5c4ab842b40355 to your computer and use it in GitHub Desktop.
Any data type that can be handled as a string by JavaScript can be sent. Here are functions that will take strings for JavaScript code, CSS styles, and images and convert them into resources the browser can use:
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 handleImageData(data, mimeType) { | |
var img = document.createElement('img'); | |
img.src = 'data:' + mimeType + ';base64,' + data; | |
return img; | |
} | |
function handleCss(data) { | |
var style = document.createElement('style'); | |
style.type = 'text/css'; | |
var node = document.createTextNode(data); | |
style.appendChild(node); | |
document.getElementsByTagName('head')[0].appendChild(style); | |
} | |
function handleJavaScript(data) { | |
eval(data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment