2

I have a JavaScript file attached to a webpage called 'navigate.js' It contains a collection of methods that look like this:

var ContractWindow;
function showContract(ContractID){
    try{
         if(ContractWindow){
            if(!ContractWindow.closed){
               ContractWindow.close;
            }
         }

        ContractWindow = window.open(contract.aspx?contractid=" + ContractID, "ContractEditor",
        "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=780,height=615");
        }
    }catch(exc){
    alert(exc.message);
    }
}

(there are similar functions to open pages for editing product categories, products, regions...etc.)

Each of several functions opens up a different editor page in its own window, with the goal that only one window of any given type (where type="ContractEditor") should be open at any given time.

If an editor (in this case the Contract Editor) is reused we want to close the previous window first so that subsequent window.open will cause the new window to come to front of any windows (have focus).

Everything works as expected until the page has been idle for approximately 10 minutes. After which the alert message reads: The object invoked has disconnected from its clients

Various tests have revealed that the exception comes from the assignment of the return value of window.open to the ContractWindow variable. If I leave out ContractWindow = and just call window.open, it works but the window does not 'pop' to the forefront which is a requirement. (window.open reuses the existing window named "ContractEditor" but does not bring it forward from the stack of open windows.)

2
  • Are you running Microsoft VBA code?
    – j08691
    Mar 12, 2012 at 16:29
  • No. Asp.net/C# on the server with javascript (and some jquery) on the client. The browser is IE 7/8
    – Cos Callis
    Mar 12, 2012 at 16:44

2 Answers 2

1

While better answers are certainly welcome I have arrived at a 'work around' that will serve to get the feature 'out the door' though I would like to get a better understanding of the cause of this exception and a 'better solution' if it exists.

Having determined that the issue arises from the attempt to assign the return value of window.open to var ContractWindow I introduced a layer of mis-direction as follows:

var ContractWindow;
function showContract(ContractID){
    try{
         if(ContractWindow){
            if(!ContractWindow.closed){
               ContractWindow.close;
            }
         }
        // assign the return of window.open to a 'guaranteed new' variable...
        var newWindow = window.open(contract.aspx?contractid=" + ContractID, "ContractEditor",
        "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=780,height=615");
        // then re-assign to the global var ContractWindow.
        ContractWindow = newWindow;
        }
    }catch(exc){
    alert(exc.message);
    }
}

I am thinking there must be something different in the way JavaScript manages object pointers... What I have done 'works' but it is not what I would call 'good'... Then again there is always this corollary to Murphy's Law:

If it's stupid but it works, it isn't stupid.

0

i had the same problem with my code, try to colne the that you get from window.open, becuse he depand on open.window status.

i used jQuery.extend(true, {}, data); to clone the data i get from window.open. it may work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.