Solved

Window.close of javascript is not working

Posted on 2013-01-16
17
475 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
 
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
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 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now