Solved

Window.close of javascript is not working

Posted on 2013-01-16
17
483 Views
Last Modified: 2013-01-31
I have two asp.net applications.

One app is referring a page in other app.
On that page i have a cancel button on which i am calling window.close() JavaScript function.

But when the app that refers to the page in other app, this cancel button is not working.

Please guide,
Thanks
0
Comment
Question by:Aspnet_9
  • 9
  • 7
17 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38782559
can u post the relevant code in the page which you try to close?
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38782565
try one of the following:
self.close(),
window.parent.close();
var win = window.open("","_self");
win.close();
0
 

Author Comment

by:Aspnet_9
ID: 38782591
This is function being called on page with cancel button.
        function CancelClick() {
            window.self.close();
        }

Code used to call the above page

            this.winNotes.AutoLoad.Url = System.Web.Configuration.WebConfigurationManager.AppSettings["Te"] + "/views/Note/Add.aspx;
            this.winNotes.LoadContent();
            this.winNotes.Show();
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 42

Expert Comment

by:sedgwick
ID: 38782596
did u try what i've suggested?
which browser you use?
0
 

Author Comment

by:Aspnet_9
ID: 38782621
I have tried all the above options mentioned by you. None is working.

I am using IE,Firefox
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38782631
when running in FF do you get any errors?
0
 

Author Comment

by:Aspnet_9
ID: 38782640
No, its not.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38782652
In FF, window.close() will close only if opened via window.open:

window.close
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38782670
try the following:

function winClose()
{
var win=window.open("","_self");
win.close();
}

Open in new window

or
function winClose()
{
window.top.opener=null;
window.close();
}

Open in new window

or
function closeWindow()
{
window.open('','_parent',''); 
window.close();
}

Open in new window


if not set your firefox browser:

1.

input "about:config " to your firefox address bar and enter;

2.

make sure your "dom.allow_scripts_to_close_windows" is true


fromMozilla Firefox JavaScript Window.Close() Not Working
0
 

Author Comment

by:Aspnet_9
ID: 38782672
I cannot open the window using window.open as it is being called programatically from other app.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38782848
i understand that you can't i'm just showing you FF restrictions.
did u try the other suggestions?
0
 

Author Comment

by:Aspnet_9
ID: 38782875
Unfortunately they are not working.

is there any way in can close the window using c# code in code behind?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38782890
you can try the following:

ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "close", "window.close();", True);

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38782899
if its not working try:
protected void Page_Load(object sender, EventArgs e)    
{
    Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "close", "window.onunload = CloseWindow();");
}

Open in new window


and in your aspx page add closePage function:
function closePage() {
    window.close();
}

Open in new window

0
 

Author Comment

by:Aspnet_9
ID: 38782939
this is again calling the javascript through codebehind,
I dont think its going to work
0
 
LVL 6

Expert Comment

by:esolve
ID: 38786061
Not sure if I understand your scenario but if you would like to close a page from a button click I usually do the following. Add an image to your page which will prevent the page from doing a postback. We're using nice images which looks like a button.

Then in the code behind of the same page you add the following

imgCancel.Attributes.Add("onclick", "window.close();");

You can also force a refresh on the parent page causing it to reload.
0
 

Author Closing Comment

by:Aspnet_9
ID: 38840926
ok
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

856 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