Forum Discussion

kevin_kapell's avatar
kevin_kapell
Frequent Contributor
8 years ago
Solved

Why do I get an error message when closing a tab

I use the following function to close a browser page tab in IE 11.

The tab is closed but I get an error in the log that the tab was not closed.

Any ideas why and how I can avoid the error?

 

function CloseTab(URL)
{
Log.Event("function CloseTab")
var browser = Sys.Browser();
Sys.Browser().Page(URL).Close();
}

 

Thanks

Kevin

  • Ryan,

    I like your solution and I think I can use elements of it for other things.

     

    However, my co-worker came up with the following that worked.

     

    function CloseTab(URL)
    {
      var browser = Sys.Browser("*");
       var page = browser.Page("*");
       Sys.Browser().Page(URL).Keys("^w")

    }

3 Replies

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    function CloseTab(URL) {
        Log.Event("function CloseTab")
        try {
            //ghetto work around
            Log.Enabled = false;
            var browser = Sys.Browser();
            Sys.Browser().Page(URL).Close();
        catch(e) {
        }
        finally {
            Log.Enabled = true;
        }
    }
    • kevin_kapell's avatar
      kevin_kapell
      Frequent Contributor

      Ryan,

      I like your solution and I think I can use elements of it for other things.

       

      However, my co-worker came up with the following that worked.

       

      function CloseTab(URL)
      {
        var browser = Sys.Browser("*");
         var page = browser.Page("*");
         Sys.Browser().Page(URL).Keys("^w")

      }

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      lol

       

      I'm giving you kudos for that on the basis that it's probably the dirtiest workaround I've seen on here! :smileyvery-happy:

       

      (Although, despite it's dirtiness, it should work. Sort of. If you try and close a page that doesn't exist, you won't get an error now ...)