Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close window button without prompt

Status
Not open for further replies.

markronz

IS-IT--Management
Mar 20, 2007
93
US
Hello everyone-
I am just trying to create a button to close an IE window. I can do this but it prompts me and says "The webpage you are viewing is trying to close the window. Do you want to close the window?"

Does anyone know how to create a close button that doesn't have that prompt?

Thanks!
-Mark
 
Javascript [tt]window.close[/tt] method should do this for you. What are you doing at the moment? Can we see some code? It is possible that MS has gone to trouble to make it impossible for us to do it without the prompt, but I don't usually remember prompt on other popup closings. Although I hardly ever use IE outside testing environment.
 
I apologize I should have known to put some of my code on my initial post! Here is my code so far. Basically this is a VBScript that launches a IE window:

Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Visible = True
objExplorer.ToolBar = False
objExplorer.StatusBar = False
objExplorer.Navigate "about:blank"
objExplorer.Document.Body.InnerHTML = "<p>Assist Complete. <i>(You may now close this window.)</i></p><p><BUTTON TYPE=BUTTON NAME=""Close"" TABINDEX=0 onClick=""window.close()"">Close </BUTTON></p>"

Do While TypeName(objExplorer) = "IWebBrowser2"
WScript.Sleep 1000
Loop

WScript.Echo "Window closed...proceed with script"



So it's pretty much just that one line of HTML where I show two sentences and a close button. When I use the window.close() in this way it prompts me. Ideally I'd just like the Close button to close the window the same way a Alt+F4 or the X in the upper right of the window would...
 
I don't ever use VBScript for client side programming because it is only supported by IE, so I can't help you much. Hope someone else can.
 
Put the window.close() method in an anchor tag instead of a <button> tag. You can use CSS to make the anchor look like what you want.

90% sure of this, you can try a very quick test by replacing your innerHTML line of code with this:
Code:
objExplorer.Document.Body.InnerHTML = "<p>Assist Complete. <i>(You may now close this window.)</i></p><p><a href="javascript:window.close()">Close </a></p>"



[monkey][snake] <.
 
P.S. I know you are using VBScript, however the code will still work.

[monkey][snake] <.
 
It's always going to prompt the user to close. This is a security mechanism built into all the browsers. Otherwise, any web page could close your browser without your permission.

The only way around it is if you specifically created the window from a previous page using window.open. Then, on that window that was created, you can call window.close and it will not prompt.

Ron Wheeler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top