Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to close the tab which displays my webpage,

on the load . But browser does not allow to close the window by javascript as long as it is not opened by javascript

i have two div when secound div display i want an alert and close the current window..

Note -i have not opend the tab(window) by javascript
Posted
Comments
Xiao Ling 20-May-14 5:18am    
If the window is not opened by JavaScript, how can you get the window reference? If there is no window reference stored with JavaScript, how can you close the window through JavaScript?
vbmike 20-May-14 14:46pm    
Have you tried simply window.close()?
Umesh Parshad 21-May-14 0:41am    
yes i have tried but in firfox its not working......

What you have experienced is part of the 'protection' browsers give you while on the wild...
Closing (and opening) windows from code is considered 'popup' activity and not tolerated - by default.
So when executing window.close(); browsers will send the user a message, and ask if he agree to close the window...The only exception is when the window was opened by window.open(), which is not your case.
You have to consider your application design...
 
Share this answer
 
The close() method closes the current window.

JavaScript
<form method="post">
<input type="button" value="Close Window">
onclick="window.close()">
</input></form>


some references.. :)


Window.Close

Window.Close Method Example

HTML Close Window Code
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 21-May-14 7:31am    
I believe that OP's problem that such a JS command will prompt the end user with a somehow confusing question. He wants to bypass it...
Hi Umesh,

you can try this link

http://www.w3schools.com/jsref/met_win_close.asp[^]

Good Luck
 
Share this answer
 
Comments
Kornfeld Eliyahu Peter 21-May-14 7:31am    
I believe that OP's problem that such a JS command will prompt the end user with a somehow confusing question. He wants to bypass it...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900