Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Close browser window.

Close browser window.

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascriptasp-nettools
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Morgs Morgan
    wrote on last edited by
    #1

    Hi guys am trying close the browser window once user clicks button 'Exit browser', in asp.net I tried the following but it won't work

    string scriptor = "<script type=javascript>window.close();</script>";
    if(!ClientScript.IsStartupScriptRegistered("clientScript"))
    {
    ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", scriptor);
    }

    and

    Response.Write("<script type=text/javascript>self.close()</script>");

    this is in my click event Does anyone know how i can fix this one? please help

    M S 2 Replies Last reply
    0
    • M Morgs Morgan

      Hi guys am trying close the browser window once user clicks button 'Exit browser', in asp.net I tried the following but it won't work

      string scriptor = "<script type=javascript>window.close();</script>";
      if(!ClientScript.IsStartupScriptRegistered("clientScript"))
      {
      ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", scriptor);
      }

      and

      Response.Write("<script type=text/javascript>self.close()</script>");

      this is in my click event Does anyone know how i can fix this one? please help

      M Offline
      M Offline
      Martin Jarvis
      wrote on last edited by
      #2

      What happens if you add an 'onclick' attribute to your button as set is equal to window.close(); Seems a bit unnecssary to require a postback to the server for this.


      Freestyle Interactive Ltd | Martin on .Net

      1 Reply Last reply
      0
      • M Morgs Morgan

        Hi guys am trying close the browser window once user clicks button 'Exit browser', in asp.net I tried the following but it won't work

        string scriptor = "<script type=javascript>window.close();</script>";
        if(!ClientScript.IsStartupScriptRegistered("clientScript"))
        {
        ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", scriptor);
        }

        and

        Response.Write("<script type=text/javascript>self.close()</script>");

        this is in my click event Does anyone know how i can fix this one? please help

        S Offline
        S Offline
        Sandeep Mewara
        wrote on last edited by
        #3

        Try this:

        string script = "window.close();";
        System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CloseWindow", script, true);
        // In case no ScriptManager then:
        //Page.RegisterClientScriptBlock(Page, this.GetType(), "CloseWindow", script, true);

        This should work.

        M 1 Reply Last reply
        0
        • S Sandeep Mewara

          Try this:

          string script = "window.close();";
          System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "CloseWindow", script, true);
          // In case no ScriptManager then:
          //Page.RegisterClientScriptBlock(Page, this.GetType(), "CloseWindow", script, true);

          This should work.

          M Offline
          M Offline
          Morgs Morgan
          wrote on last edited by
          #4

          Hi thanks Sandeep, Well, this works for IE but unfortunately it won't work for Fire Fox for some reason...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups