Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Jan 2010
    Posts
    2
    Vote Rating
    0
    ole_witthoeft is on a distinguished road

      0  

    Default Unanswered: window.open not working?

    Unanswered: window.open not working?


    Is there a way to get "window.open" working in javascript running in a packaged app?

    I know there are possibilities like "Ion.util.openUrl(...)" for Default-Browser-Windows and "Ion.ui.Window({url: _url, title: 'Second Window'})" for Application-Windows. But I have some old views running in my app which use "window.open".

  2. #2
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    54
    Vote Rating
    1
    Answers
    2
    maikhorma is on a distinguished road

      0  

    Default Wrap window.open?

    Wrap window.open?


    I'm brand new to packager so forgive me if this is ignorant but couldn't you wrap the window.open [1] command?

    [1] http://stackoverflow.com/questions/9172505/how-to-override-the-window-open-functionality


  3. #3
    Sencha User
    Join Date
    Jan 2010
    Posts
    2
    Vote Rating
    0
    ole_witthoeft is on a distinguished road

      0  

    Default


    Seems like a good and simple solution - Thank you.
    Gonna try it as soon as we focus on this project.

  4. #4
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    54
    Vote Rating
    1
    Answers
    2
    maikhorma is on a distinguished road

      0  

    Default


    Just implemented this for my app:
    Code:
    //only apply if running in packaged app
    if(window.Ion){
        window.open = function (open) {
            return function (url, name, features) {
                //call ion function instead
                return Ion.util.openUrl(url);
            };
        }(window.open);
    }
    A couple of notes:
    • Ion package returns boolean, normal javascript will return a window object. In my case I didn't care, but if you expect to do anything with the return, this solution won't work
    • The only reason I do "if window.Ion" is because I'm continuing to support the standard webapp as well. If you're doing packaged only, this is not necessary (but doesn't hurt).
    • I put this in the launch() of my app, but it can be anywhere as long as it's executed before you try to call window.open.

  5. #5
    Sencha User
    Join Date
    Aug 2013
    Posts
    3
    Vote Rating
    0
    ngonqua is on a distinguished road

      0  

    Default


    To avoid circular calls, you need to stash away the original window.open function in variable.
    A nice way (that doesn't pollute the global namespace) is to use a closure. Pass the original window.open function to an anonymous function as an argument (called open below). This anonymous function is a factory for your hook function. Your hook function is permanently bound to the original window.open function via the open argument:

    window.open = function (open) {
    return function (url, name, features) {
    // set name if missing here
    name = name || "default_window_name";
    return open.call(window, url, name, features);
    };
    }(window.open);

    Can somebody explain more about this ?
    NgonQua.Net - Photos Sharing

  6. #6
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    54
    Vote Rating
    1
    Answers
    2
    maikhorma is on a distinguished road

      0  

    Default


    Break it up a little:

    Code:
    var openWrapper =  function (originalOpen) {
      console.debug('original open exists here:' +  originalOpen);
      var newOpen = function (url, name, features) {
        console.debug('original open STILL exists here:' +  open);//<-- open is passed in by scope
        // set name if missing here
        name = name || "default_window_name";
        return originalOpen.call(window, url, name, features); 
      };
      return newOpen;
    };
    Here you have a 'utility' that will create a new function that (by default) will have access to the parent's scope. Then just return it.

    Then tell it to wrap something:
    Code:
    var openWrapped = openWrapper(window.open);
    Then use it:
    Code:
    openWrapped('www.google.com')
    Was that any clearer?

Thread Participants: 2