Click here to Skip to main content
14,971,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hello Team i am just open a tab  with java script in c#
//here
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.open('");
sb.Append(url);
Session["url"] = url.ToString();
sb.Append("');");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(),
"script", sb.ToString());
//this is f9 perfactly ...
and i want to close the open tab(url) after 40 seconds
how it possible
i am using
string jScript = "<script>window.close();</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "btnsubmit", jScript);
//this work with btnsubmit on any other form
but here  is  not working ..
i am just want to perform it with timer event or any other option you have please suggest..
Posted
Updated 28-Oct-20 3:54am

You are doing it wrong. You already use window.open. This call returns window object which you discard. But you can use it:
JavaScript
var someWindow = window.open(/* ... */);

// ...

someWindow.close();


—SA
   
Comments
Aditya Chauhan 27-Mar-15 14:45pm
   
how it declared in cod behind pls suggest ...?
Sergey Alexandrovich Kryukov 27-Mar-15 16:29pm
   
It has nothing to do with code behind... Code behind does not remove pages, it only responds to HTTP requests and generates HTTP response. In a response, you can generate some text of a script, but manipulation with the pages can be done only by the script, on the client side.
—SA
Aditya Chauhan 28-Mar-15 4:11am
   
if it possible in the Php...why this not possible in asp.net..
i will provide you my credential for test it
   
You are right. Moreover, it has nothing to do with code behind, no matter PHP or ASP.NET. :-)
—SA
Do it in Javascript as part of the page script:
JavaScript
setTimeout("window.close()",40000);
should do it
   
Comments
Aditya Chauhan 27-Mar-15 14:45pm
   
how it is possible pls suggest me
this is code behind code and i open a new tab as like www.google.com
how can i close it
You need to use:
string jScript = "<script>indow.open('', '_self', ''); window.close();</script>"
   
v2
Comments
Dave Kreskowiak 28-Oct-20 11:52am
   
You might want to look at the dates on questions before answering them.

I seriously doubt the OP is still working on this 5 years later, and other answers have already covered the topic.

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