window.close not working

485 views
Skip to first unread message

solanki...@gmail.com

unread,
Nov 12, 2014, 7:03:03 AM11/12/14
to blin...@chromium.org
Hi.
I am using window.showModalDialog() method in my application, which was deprecated later, by Chrome. So, I made a registry entry to make it work till 30th March 2015(this solution found when I googled). But again after updating chrome, window.close() method stopped working. My modal window is not getting closed using this method. After searching on google, I found that, since I did not open my window using window.open(), window.close() wont close that window. I want my modal window to be closed. Any solution or suggestion is welcomed. Thank You.

greg...@gmail.com

unread,
Nov 12, 2014, 4:16:04 PM11/12/14
to blin...@chromium.org, solanki...@gmail.com
Have you considered using the new dialog element rather than window.showModalDialog()?


https://github.com/GoogleChrome/dialog-polyfill

For porting existing code which already uses window.showModalDialog() with minimal changes you could even put an iframe inside a dialog element.

solanki...@gmail.com

unread,
Nov 13, 2014, 2:13:27 AM11/13/14
to blin...@chromium.org, solanki...@gmail.com, greg...@gmail.com
Hi,
Thank You for your reply.I tried using the dialog element but it allows to access other contents of the HTML page even when the dialog box is open. And to avoid this I used showModalDialog.

PhistucK

unread,
Nov 13, 2014, 2:24:30 AM11/13/14
to ankit solanki, blink-dev, greg...@gmail.com
You need to create an element below it (z-index-wise) that covers the page (position: fixed; top: 0; left: 0; right: 0; bottom: 0) and then the user will not be able to interact with the content below it.


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.

Matt Falkenhagen

unread,
Nov 13, 2014, 2:53:29 AM11/13/14
to PhistucK, ankit solanki, blink-dev, greg...@gmail.com
You shouldn't need that extra element. User interaction with elements outside the <dialog> is expected to be blocked. What do you mean by "access other contents"?

<dialog> does have a ::backdrop pseudo-element that is good for visually covering the rest of the page, but it's not needed to block user interaction.

PhistucK

unread,
Nov 13, 2014, 12:45:07 PM11/13/14
to Matt Falkenhagen, ankit solanki, blink-dev, Greg Lowe
Right, sorry. dialog.showModal() instead of dialog.show() does the trick.


PhistucK

greg...@gmail.com

unread,
Nov 13, 2014, 5:31:11 PM11/13/14
to blin...@chromium.org, fal...@chromium.org, solanki...@gmail.com, greg...@gmail.com
Has anyone see a good article which explains how to port code from window.showModalDialog() to Dialog.showModalDialog()? Ideally Including tricks like using an iframe in a dialog to mimic window.open() usage in an existing codebase. An article like this will definitely make it easier for other browsers to push for window.showModalDialog() api removal.

Simon Pieters

unread,
Nov 14, 2014, 3:14:49 AM11/14/14
to blin...@chromium.org, greg...@gmail.com, fal...@chromium.org, solanki...@gmail.com
On Thu, 13 Nov 2014 23:31:11 +0100, <greg...@gmail.com> wrote:

> Has anyone see a good article which explains how to port code from
> window.showModalDialog() to Dialog.showModalDialog()? Ideally Including
> tricks like using an iframe in a dialog to mimic window.open() usage in
> an
> existing codebase. An article like this will definitely make it easier
> for
> other browsers to push for window.showModalDialog() api removal.

http://thinkingoutsidetheanglebrackets.blogspot.se/2014/09/removal-of-showmodaldialog-and.html

--
Simon Pieters
Opera Software

ankit solanki

unread,
Nov 24, 2014, 5:06:47 AM11/24/14
to Simon Pieters, blin...@chromium.org, greg...@gmail.com, fal...@chromium.org
Hi,
Thank You for the solution. I gave a try to use dialog.showModal() and it is working for me. It disables the background screen when the message is displayed to the user, but the problem now I am facing is, the control moves ahead even when the message is still displayed on the screen to the user. How should I control that ?
--
Thanks & Regards,
  Ankit Solanki

PhistucK

unread,
Nov 24, 2014, 5:09:05 AM11/24/14
to ankit solanki, Simon Pieters, blink-dev, Greg Lowe, Matt Falkenhagen
You will have to be somewhat more illustrative, because the issue is not clear. A screenshot or a screencast would probably help.


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.

ankit solanki

unread,
Nov 24, 2014, 5:54:12 AM11/24/14
to PhistucK, Simon Pieters, blink-dev, Greg Lowe, Matt Falkenhagen
Ok.I have a page1 from where I call page2 using window.open(). In page2 I have a <dialog> , in which I have a question to confirm with user, whether to clear the contents of the page, with two options Yes or No. Depending on the users input, I call the respective function. Now the problem is, I have put an alert message in page1, after window.open() which pops up before my call for page2 is completed. I want that alert message to be popped up only after user enters his choice whether to clear the contents of the second page or no. If any more clarification needed, do ask for it.

PhistucK

unread,
Nov 24, 2014, 6:30:58 AM11/24/14
to ankit solanki, Simon Pieters, blink-dev, Greg Lowe, Matt Falkenhagen
Sounds like something you should figure out yourself, it is specific to your implementation. Just setTimeout that alert or something (or better yet, use <dialog> instead of alert).


PhistucK

ankit solanki

unread,
Nov 24, 2014, 6:55:32 AM11/24/14
to PhistucK, Simon Pieters, blink-dev, Greg Lowe, Matt Falkenhagen
My motive behind putting alert is only to check whether the control runs ahead, before accepting users choice. And it does run ahead. My requirement is, any line written after window.open() should not be executed unless and until the user does not enter his choice. I don't know how to achieve this.

PhistucK

unread,
Nov 24, 2014, 6:58:35 AM11/24/14
to ankit solanki, Simon Pieters, blink-dev, Greg Lowe, Matt Falkenhagen
This is exactly the problematic feature that showModalDialog had and the reason for its removal. You cannot achieve that, you have to change your code to use callbacks/promises and the like.


PhistucK

ankit solanki

unread,
Nov 25, 2014, 7:07:22 AM11/25/14
to PhistucK, Simon Pieters, blink-dev, Greg Lowe, Matt Falkenhagen
Thank You for clearing me on this. I am using callbacks now and it is working for me.

jerzyg...@gmail.com

unread,
Jan 8, 2015, 8:09:22 AM1/8/15
to blin...@chromium.org, fal...@chromium.org, solanki...@gmail.com, greg...@gmail.com
Have a look at my showModalDialog polyfill: https://github.com/niutech/showModalDialog - it uses a modal dialog and generators to block execution.
Reply all
Reply to author
Forward
0 new messages