Skip to content

Instantly share code, notes, and snippets.

@neutraltone
Last active January 14, 2016 00:12
Show Gist options
  • Save neutraltone/afe31f86fe43f2a20152 to your computer and use it in GitHub Desktop.
Save neutraltone/afe31f86fe43f2a20152 to your computer and use it in GitHub Desktop.
Dialog Example
<dialog id="dialog">
<h3>Are you sure?</h3>
<p>You’ve pressed a big red button. It might do… something.
<div>
<button id="okay">Okay, go ahead</button>
<button id="cancel">Cancel</button>
</div>
</dialog>
/**
* Opening dialog
*/
var dialog = document.getElementById('dialog');
dialog.show();
document.getElementById("cancel").onclick = function() {
dialog.close();
}
/**
* Check for dialog support
*/
var testdialog=document.createElement("dialog");
testdialog.setAttribute("open", "");
if (testdialog.open==true){
// browser supports the dialog element
} else {
// browser doesn’t support the element: load a polyfill
}
dialog {
font-family: Avenir, sans-serif;
width: 25%;
text-align: center;
border: 3px solid;
}
dialog div {
display: flex;
justify-content: space-between;
}
dialog::backdrop {
background: rgba(0,0,0,0.9);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment