Skip to content

Commit

Permalink
Resolves pebble#162 - data URI now loads in iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedn committed Jun 5, 2020
1 parent 1bf6db0 commit 65106c7
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions dev/emulator.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<title>Config Page Emulator</title>
</head>
<script>
// Must wait for onload for appendChild to work
window.onload = function () {
function getQueryParam(variable, defaultValue) {
var query = location.search.substring(1);
var vars = query.split('&');
Expand All @@ -22,13 +24,26 @@
var data = decodeURIComponent(location.hash.substring(1));

// Check if we dealing with a base64 encoded URI
if (data && data.charAt(0) !== '<') {
data = window.atob(data).replace('$$RETURN_TO$$', returnTo);
window.location.href = 'data:text/html;base64,' + encodeURIComponent(window.btoa(data));
} else if (data) {
data = data.replace('$$RETURN_TO$$', returnTo);
window.location.href = 'data:text/html;charset=utf-8,' + encodeURIComponent(data);
if (data) {
if (data.charAt(0) !== '<') {
data = window.atob(data).replace('$$RETURN_TO$$', returnTo);
data = 'data:text/html;base64,' + encodeURIComponent(window.btoa(data));
} else {
data = data.replace('$$RETURN_TO$$', returnTo);
data = 'data:text/html;charset=utf-8,' + encodeURIComponent(data);
}
// Create a new iframe element with our data URI
var iframe = document.createElement("iframe");
iframe.src = data;
// Make the iframe fill the entire display
iframe.frameborder = "0";
iframe.style = `position:fixed; top:0; left:0; bottom:0; right:0; width:100%; height:100%;
border:none; margin:0; padding:0; overflow:hidden; z-index:999999;`;
// Append iframe to body
document.body.appendChild(iframe);

}
};
</script>
<body>
</body>
Expand Down

0 comments on commit 65106c7

Please sign in to comment.