Open macmessa opened 5 years ago
I was waiting for such PR how years and finally found it !!! Thank you a LOT @macmessa ! This works perfectly.
Please add also this updated demo.html
page (and remove demo-modal.html
file) which shows how to use it and how nested dialogs work:
<!DOCTYPE html>
<html>
<head>
<title>showModalDialog polyfill demo</title>
<script src="showModalDialog.js"></script>
</head>
<body>
<h1>showModalDialog polyfill demo</h1>
<form action="">
<p><input id="x" placeholder="Input number" /></p>
<p><input id="button1" type="button" value="Show Modal Dialog using yield" /> <span id="result1"></span></p>
<p><input id="button2" type="button" value="Show Modal Dialog using async/await" /> <span id="result2"></span></p>
<p><input id="button3" type="button" value="Show Modal Dialog using eval" /> <span id="result3"></span></p>
<p><input id="bt_close" type="button" value="Close dialog" /></p>
</form>
<hr />
<p>Dialog received arguments: <b><span id="arg"></span></b></p>
<script>
x = document.getElementById('arg').innerHTML = window.dialogArguments;
if (x) {
window.returnValue = parseFloat(x) * parseFloat(x); // calc x^2 and return result
}
</script>
<script>
// close most recent dialog
document.getElementById('bt_close').addEventListener('click', function() {
window.close();
});
//using yield
document.getElementById('button1').addEventListener('click', function() {
spawn(function*() {
var opt = "dialogWidth:500px;dialogHeight:350px";
var ret = yield window.showModalDialog("demo.html", document.getElementById("x").value, opt);
document.getElementById('result1').innerHTML = "Returned from modal: <b>" + ret + "</b>";
});
});
//using async/await
document.getElementById('button2').addEventListener('click', async function() {
var opt = "dialogWidth:500px;dialogHeight:350px";
var ret = await window.showModalDialog("demo.html", document.getElementById("x").value, opt);
document.getElementById('result2').innerHTML = "Returned from modal: <b>" + ret + "</b>";
});
//using eval
document.getElementById('button3').addEventListener('click', function() {
var opt = "dialogWidth:500px;dialogHeight:350px";
var ret = window.showModalDialog("demo.html", document.getElementById("x").value, opt);
document.getElementById('result3').innerHTML = "Returned from modal: <b>" + ret + "</b>";
});
</script>
</body>
</html>
Doesn't work in Firefox at all
Uncaught (in promise) TypeError: showModalDialog.caller is null in line 51
.
That line 51 should be removed completely.Uncaught (in promise) TypeError: caller is null
That's because Function.caller
is deprecated - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller I have no idea how to solve that.
- Works perfectly in Chrome.
- Edge works fine.
- Internet Explorer 11 - only eval version works because others are not supported
Doesn't work in Firefox at all
- error
Uncaught (in promise) TypeError: showModalDialog.caller is null in line 51
. That line 51 should be removed completely.- After that's done, we get another error -
Uncaught (in promise) TypeError: caller is null
That's becauseFunction.caller
is deprecated - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller I have no idea how to solve that.
ASAP I'll add the updates you suggested and take a look at this caller
issue.
I've accidentally closed the pull request.
Thanks! You will have to find the way around using deprecated Function.caller
.
In a meantime I created my repo which I will use in one of my legacy projects because this repo is quite stale and PRs can sit there not merged for ages :(
I was allowed to drop IE support in project and that way I could drop eval version which requires caller
. Here is repo https://github.com/DarkSide666/showModalDialogMulti. Works flawlessly in all browsers except IE.
Adding: