Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Window.close of javascript is not working

Posted on 2013-01-16
17
Medium Priority
?
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
17 Comments
 
LVL 42

Expert Comment

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

Accepted Solution

by:
Meir Rivkin earned 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 42

Expert Comment

by:Meir Rivkin
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:Meir Rivkin
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:Meir Rivkin
ID: 38782652
In FF, window.close() will close only if opened via window.open:

window.close
0
 
LVL 42

Expert Comment

by:Meir Rivkin
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:Meir Rivkin
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:Meir Rivkin
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:Meir Rivkin
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

618 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