Solved

More control over Javascript Windows

Posted on 1998-05-13
20
193 Views
Last Modified: 2008-03-06
I am launching a new window from the first page of a site within which everything will then be loaded.

My question is how can I get the opening window to either close or minimise after if has opened my new window.  What I want to be left with is just the window in the middle of the screen without the opener in the background.

My base platform is IE4.  I have searched everywhere for a solution but non has been forthcoming.  Also is it possible when opening the window to get rid of the really annoying controlbar at the top.  I have everything turned off that I know of but I still have the thick controlbar at the top.  If it can't turned off can it be made thinner?

At the moment I am just using a pretty standard opener script:-

var newWindow;
winOpts='menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,width=570,height=380';

      self.name = 'opener';
      Urlvar = "index2.htm";
      PCMBrowser = window.open(Urlvar,'newWindow',winOpts);

I'll start the points at 50 incase (as I suspect) the answer comes back as "Not Possible".  If it starts getting interesting I'll up the points.

Trevor.
0
Comment
Question by:Trevor013097
  • 9
  • 4
  • 3
  • +3
20 Comments
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
Edited text of question
0
 
LVL 4

Expert Comment

by:jbrugman
Comment Utility
Try to use the self.close(); command. (with an onBlur option ore something like that)
onBlur="self.close();"
0
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
You could use close(), as jbrugman sais, but even just after the open(), i guess.

window.open(Urlvar, ...);
window.close();

About the control bar: do you mean the "titlebar"?
If so, there's a "titlebar" Window's feature, but it has been implemented in NN4 (IE4), and to set it to "no", you need a signed script.

Regards, julio
0
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
Must be the heat (26 is hot for the UK!!) but I didn't even think of close();

however there is a problem with that method.  IE4 prompts you to confirm you wish to close the window with the message:-

-----
The web page you are viewing is trying to close the window.

Do you want to close the window?

Yes     No
-----

With regards the controlbar, yes I am referring to the title bar, what exactly is a signed script and how would I get one to do what I want.  Is it simply a Javascript which has been produced with a certificate which you tell your browser to accept as with Applets etc.

Trevor.

0
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
To unconditionally close() a window you again need signed scripts.

Here are some additional infos from Netscape's JS Reference:

"The close method closes only windows opened by JavaScript using the open
method. If you attempt to close any other window, a confirm is generated, which lets
the user choose whether the window closes. This is a security feature to prevent "mail
bombs" containing self.close(). However, if the window has only one document
(the current one) in its session history, the close is allowed without any confirm. This
is a special case for one-off windows that need to open other windows and then
dispose of themselves."

About signing scripts, i've never done that, but have - again from Netscape site - downloaded a "JS Security Guide" (76Kb). Cannot remember the Url, but you should easily be able to find it in Netscape's developer corner, or give me your mail address so that i can send you the stuff.

-julio
0
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
julio,

I don't need to worry about the close() security restriction having read your offering.  I am developing a front end for a CD-ROM which uses the autorun to launch index.html which then in turn uses window.open to give me a flotaing window without the usual IE baggage which looks more like the sort of menu system you get on coverdisks.

Seeing as the window I wish to close has no history it won't prompt for the confirm.  In my tests so far I had of course loaded something else and then opened the page manually and hence had a history.

If you would liek to post an answer I'll grade it 'A'.  If you think the points are a bit low then just say.

Trevor.


0
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
julio,

Just tested the close() having loaded the first page directly, so that there was not a history and it still prompted me on closing.

Any thoughts?


0
 

Expert Comment

by:btphelps
Comment Utility
If the browser is already open for any reason, you will get the prompt.

The first alternative, as somewhat described before, is to load a new window, e.g.,

<SCRIPT LANGUAGE="javascript">
<!-- Engage cloaking device

parentwinattr=window.open("filename.html", 'parentwinHome', "width=445,height=475,toolbar='NO',directories='NO',menubar='NO',status='NO',scrollbars='NO',copyhistory=1")
var helpWin=null;
self.close();

// Disengage cloaking device -->
</SCRIPT>

Alternatively, you can try adding a statement to your BODY tag:

ONLOAD="window.open('filename.html' target='_parent')"

which would put the filename back into the parent window without technically closing it. You can also write a function for the window.open statement above and substitute it in the BODY tag ONLOAD= parm.

Brian
0
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
btphelps,

That still comes up with the same problem, I get a prompt to close the window even though I double-clicked on the file from explorer.

Why, if I am supposed to be able to close it without prompt if history is empty, am I still getting a prompt.  If I have a default page set in my options will this always be in my history even if I double-click a different file to open the browser?

Trevor.
0
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
I've tried this on NN4.04, and it works as expected (even if i do have a home page set):

--//--
<HTML>
  <HEAD>
    <SCRIPT LANGUAGE="Javascript"><!--
      function doLoad() {
        self.open("next.htm");
        self.close();
      }
    // --></SCRIPT>
  </HEAD>
  <BODY onLoad="doLoad()">
  </BODY>
</HTML>
--//--

?? julio
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:julio011597
Comment Utility
Have you tried closing the original window from within the new one?

if (windowName)  windowName.close();
0
 
LVL 2

Expert Comment

by:cyberwizz
Comment Utility
I did a lot of research, experimentation, and trial and error on this topic as I built a custom, cross-platform  HTML/JavaScript help system using pop-up windows earlier this year.

While  Netscape says that a brand new browser session opened with window.open, when closed using self.close() or its ilk,  will not display a prompt, for some reason no one at Microsoft read Netscape's documentation. IE4, in my experience, _always_ displays the prompt. No workaround I found got rid of it. I believe the ONLOAD..._top trick worked to avoid the prompt in Navigator 4.04, which has a bug having to do with self.close(), but it didn't work in IE4.

I don't think there is a solution to this question. Call this an answer if you want, though not the one you want to get.

Brian
0
 

Expert Comment

by:btphelps
Comment Utility
IE can run in Kiosk mode, can't you have a shortcut on the cd with
iexplore -k file:\index.html

That would allow you to have a background of choice in index.htm and open a new page on top of that except a possible problem is MSIE not liking location.hrefs to be changed locally.

Now you have a full screen, no menues or bars perhaps it isn't needed anymore...

0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
mplungjan,

Absolutely brilliant.  Where on earth did you find the kiosk mode documented.  It is even better than what I asked for.  Submit an answer and the points are yours.

Sorry I couldn't give points to everyone but in all fairness mplungjan has come up with a suitable solution for IE which I did specify in my original question whereas all others were for NN4.

Trevor.

0
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
IE can run in Kiosk mode, can't you have a shortcut on the cd with
iexplore -k file:\index.html

Glad to be of service, did take some testing first...

Michel
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 100 total points
Comment Utility
Hi All,

I think I have just accidentally stumbled across an extremely neat way to close window that was NOT opened with Javascript without causing any alerts.  Could someone confirm it.  I checked all my option settings and I think I have most relevant warnings on.

Basically I used an IFRAME (this will therefore only work in IE) and in that I frame the document it loaded closed itself.  Didin't get any alerts.  This is the code I had:

Main Page:

<html>

<head>
<title>Parent Document</title>
</head>

<body>
<Iframe id="Child_Document" src="popup.html" onLoad="alert('Finished');"> </iframe>
</body>

</html>


Child Page (called popup.html):

<HTML>
<HEAD>
<TITLE>Open Pop-up that auto closes after 5 seconds</TITLE>
<SCRIPT LANGUAGE="Javascript">
<!--

function closeNow() {
   self.close();
}

//-->
</SCRIPT>
</HEAD>

<BODY onLoad="setTimeout('closeNow()', 5000);">

This will close after 5 seconds

</BODY>
</HTML>

Trevor.


0
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
The onLoad within the IFRAME was something else I was testing and is not relevant to the self closing.

Trevor.


0
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
It does not do anything in MSIE 3.02 - not even after loading the page containing the iframe as a new window....

Good idea, though

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Maybe it will only work in IE4, thats what I tested it one.

Trevor.

0
 
LVL 5

Author Comment

by:Trevor013097
Comment Utility
Sorry, I do not currentlyhave access to ie4

Michel
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now