Solved

Window.close of javascript is not working

Posted on 2013-01-16
17
482 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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