Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #162 - data URI now loads in iframe #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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