Now I see what you mean, by the code fragment you've shown.
The immediate "problem" is as trivial as that: you managed not to define
fnOpen
and make it visible at the point you call this function. There is nothing to help with; you did not show the appropriate code context, but this is elementary programming issue you have to sort out anyway, otherwise you cannot do any programming at all.
The problem with popup is more difficult. Certainly,
Window.showModalDialog
can work. But first of all, pay attention: it is deprecated:
Window.showModalDialog() — Web APIs | MDN[
^].
Practically, you should not use it; it would be the bad practice, from the browser compatibility standpoint.
Now, closing a window can be done from the JavaScript of the current document or from the other document. For a current document, it as trivial as this
window.close()
. You can close some other window as well, but you have to have the reference of that window object (such reference is, for example, returned by
window.open
:
Window.open() — Web APIs | MDN[
^]).
Now, the worst thing is:
it is not always possible. If the 'window' is a tab of the tabbed browser,
you cannot close it. There is nothing you can do. And if the window is shown as modal, there is no such problem, but you can close it on the same page; you don't have any running code in the parent window which could close it, because it is, well… modal.
Here is the idea:
it's the best to avoid both
Window.showModalDialog
and
window.open
. The browser will handle both cases as "pop-up window", which will be, optionally but very typically, blocked on the client-side.
For some more detail, please see my article
Modal Popup From Scratch[
^].
It explains the popular concept of "modal popup" which simulates some modal behavior on the same Web page. Not only this approach bypass the blocking, because there are not any browser windows or tabs created. You don't need to use my "from scratch" code; there are many available solutions, featuring a good number of effects, first of all, dimming (which I implement), but also many other, such as animated transition effects:
Dialog | jQuery UI[
^],
JavaScript modal popup[
^].
—SA