• Stars
    star
    177
  • Rank 215,141 (Top 5 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 10 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

window.showModalDialog polyfill using a <dialog> element

ShowModalDialog Polyfill

This is a window.showModalDialog() shim using a modal HTML5 <dialog> element and ECMAScript 2015 Generators or ECMAScript 2017 Async/Await. It was tested in the latest Google Chrome and in the latest Mozilla Firefox with the dom.dialog_element.enabled preference set to true in about:config. Just include the following HTML code before using showModalDialog function:

<script src="https://unpkg.com/showmodaldialog"></script>

Passing both window.dialogArguments and window.returnValue is supported, provided that the dialog document is on the same server as the host document.

ShowModalDialog Polyfill is using Promises, Generators, yield, async, await and the spawn function by Jake Archibald. If they are unavailable, the polyfill is using eval and JSON as a fallback, provided that statements are separated by new lines, the showModalDialog function is not nested and runs only once in a function.

Please note that native showModalDialog support is considered deprecated and it was removed from Chrome 43 and Firefox 56.

Syntax

spawn(function*() {

    //statements before showing a modal dialog

    var returnValue = yield window.showModalDialog( url [, arguments, options] );

    //statements after closing a modal dialog

});

or:

(async function() {

    //statements before showing a modal dialog

    var returnValue = await window.showModalDialog( url [, arguments, options] );

    //statements after closing a modal dialog

})();

or:

(function() {

    //statements before showing a modal dialog

    var returnValue = window.showModalDialog( url [, arguments, options] );

    //statements after closing a modal dialog

})();

where:

  • url - a string that specifies the URL of the document to load and display;
  • arguments - a variant that specifies the arguments to use when displaying the document;
  • options - a string that specifies the dialog box style, using CSS or the following semicolon-delimited attributes: dialogHeight:???px;dialogLeft:???px;dialogTop:???px;dialogWidth:???px;

When using generators or async/await, both showModalDialog and spawn functions are Promises, so you can use their then method and yield them.

When using an eval fallback, the showModalDialog function throws an exception to stop executing code until the modal is closed, then it evals the remaining code of a caller function.

In order to close the dialog from inside of it, invoke parent.document.getElementsByTagName('dialog')[0].close(); provided that both documents have the same origin.

Demo

Here is a live demo. Works best in Google Chrome.

License

ShowModalDialog Polyfill is developed by Jerzy Głowacki under Apache 2.0 License.

More Repositories

1

node.php

Run node.js apps from PHP even on a shared hosting!
PHP
812
star
2

x-frame-bypass

Web Component extending IFrame to bypass X-Frame-Options: deny/sameorigin
JavaScript
661
star
3

jxl.js

JPEG XL decoder in JavaScript using WebAssembly (WASM)
JavaScript
306
star
4

typescript-compile

Automatically compile TypeScript to JavaScript on the fly
JavaScript
290
star
5

vue-in-web-worker

Vue.js in Web Worker
Vue
212
star
6

splitbrowser

Split Browser - a minimalistic, ultra-lightweight, open source web browser based on WebKit/Ultralight/native webview with a split screen (tiled) view
C
86
star
7

qt-ultralight-browser

Ultra-lightweight web browser based on Qt Ultralight webview, powered by Ultralight HTML renderer
C++
72
star
8

carbonyl-terminal

Carbonyl Browser ❤️ Windows/Linux/MacOS/Web Terminal
Batchfile
63
star
9

amp-spectre

⚡ AMP Spectre CSS Framework
HTML
57
star
10

comic-sans-replacer

Replace Comic Sans MS font on all websites with Comic Neue
CSS
49
star
11

chrome-devtools-sidebar

Bookmarks, History, Website in Chrome DevTools Sidebar Panel
JavaScript
46
star
12

amp-browser

AMP Browser
HTML
44
star
13

priot

The Private Internet of Things (PrIoT) Manifesto
42
star
14

ECG-Analysis

ECG signal analysis in Julia
Julia
29
star
15

phooos

Pure HTML Out-Of-Order Streaming (PHOOOS) without JavaScript
HTML
27
star
16

amp-surface

⚡ AMP Surface CSS Framework
HTML
25
star
17

telegazeta-browser

On-line browser of Polish Teletext service Telegazeta & Gazeta TV Polsat
HTML
24
star
18

typescript-interpret

Interpret TypeScript using the Console/Terminal Emulator in JavaScript
JavaScript
22
star
19

grapesjs-desktop

GrapesJS Desktop app based on NW.js
HTML
21
star
20

amp-mui

⚡ AMP MUI CSS Framework
HTML
17
star
21

gwdcomponents

Google Web Designer Components
HTML
16
star
22

amp-browser-extension

AMP Browser Extension
JavaScript
16
star
23

chess-badger2040

Chess game for Badger 2040 based on MicroPython Sunfish Chess Engine
Python
15
star
24

kindle-vnc

Simple VNC-like remote desktop server & client for Kindle 3+ using plain old HTML
Python
14
star
25

multisearch

Multi search for products on eBay, AliExpress, Amazon side by side.
JavaScript
12
star
26

kindle-dashboard

Dashboard app for Amazon Kindle 3 (Keyboard) showing to-do list, news, air quality, weather forecast.
HTML
11
star
27

large-screen-data-visualization

Large screen display data visualization templates/dashboards by Lang. Archived from https://gitee.com/lvyeyou/DaShuJuZhiDaPingZhanShi/
JavaScript
10
star
28

FreeGEM-XM

FreeGEM/XM - FreeGEM desktop for DOS with multitasking
C
7
star
29

dino-badger2040

Dino Game in MicroPython on Badger 2040 e-ink device based on RP2040 microcontroller
Python
7
star
30

zimplitcms

Zimplit CMS
PHP
7
star
31

google-search-timeline

Google Search Timeline built in AMP HTML
HTML
7
star
32

google-news-fixer

Fixer for Google News - Chrome Extension
JavaScript
6
star
33

orion-desktop

Desktop code editor for web developers based on Eclipse Orion and NW.js
HTML
6
star
34

topnewsfeed

A bookmarklet showing top News Feed posts on Facebook, Twitter, VK, Google+, Soundcloud & Mixcloud profiles
HTML
6
star
35

google-news-lite

The lightweight version of Google News using Google Web Light.
HTML
5
star
36

datacompressionproxy

Data Compression Proxy extension for Google Chrome (deprecated)
JavaScript
4
star
37

voicepedia

The voice-enabled audio-visual encyclopedia, based on Wikipedia
JavaScript
4
star
38

ssid-ticker

SSID Ticker using Wireless Hosted Network on Windows
Batchfile
3
star
39

niute.ch

Personal website
CSS
3
star
40

swiftlang

Swift Language Community
3
star
41

filesovermiles

Adobe AIR client for Files Over Miles
3
star
42

wp-blank-theme

WordPress Blank Theme
PHP
2
star
43

multiwyszukiwarka

Multiwyszukiwarka produktów na Allegro, OLX, eBay obok siebie.
JavaScript
2
star
44

arduino-auto-flusher

Automatic touchless flusher controlled by Arduino
Arduino
2
star
45

AL0

Fuji Computer AL0 for Android
Java
1
star
46

internetsurfboard

Internet Surfboard web browser
C++
1
star
47

krak-bot

Chat bot for Microsoft Teams (free) using Bing AI
JavaScript
1
star
48

webscreener

Web screenshot tool based on PhantomJS - work in progress
JavaScript
1
star
49

SOA

Private project
PHP
1
star
50

Carbonyl.AppImage

Carbonyl web browser packaged as an AppImage
Makefile
1
star
51

myongo

MongoDB for MySQL
1
star
52

netrider

NetRider - WebKit-based web browser with FLTK GUI
C++
1
star