• Home
  • RSS Feed
  • Log in


Getting through Popup Blockers with window.open() in Flex
Posted by ShriKant Vashishtha terribly early in the morning: January 4th, 2009

It was a few years back when I last worked with Javascript. Things have changed significantly in between and one of the things which we people always like is the introduction of popup-blockers in browser world. I hope you remember those old days when it was a nuisance to close all those uninvited windows. Now we are living in a relatively peaceful world. But sometimes we also want to open new windows for legitimate reasons. So when I had a task to open a new browser window on button-click, I discovered the problems posed by popup-blockers. The interesting part is – window.open() behavior can be different for different browsers and popup-blockers.

One of the things which is common amongst all browsers is – popup should open from a user action like button-click, link click etc. Popup-blockers almost always block windows opened without user-actions which looks fine to me as otherwise spammers could open dozens of windows without asking you. However this posed a bit of problem in Flex for me. I wanted to open a window after invoking some backend services. As responses (results from web-services) coming from Flex events are always asynchronous, it was just not possible to open the window after having some backend interaction. I had to change some of my design.

Another problem was different browsers behaviors. In some browsers Flex based ExternalInterface.call() method works and on some navigationToURL(). While solving this problem, I came across with a good link which solves most of the window.open() issues on different browsers.

Safari poses yet another challenge when it comes to using window.focus() function. In many of the situations you’d like to open one single named window (important from usability perspective). While using the same window for a new URL, you may want to put focus on exiting window using window.focus() function. Safari doesn’t support window.focus() function. I tried to find a suitable alternative but nothing worked except close and open the window again as follows:

var newwindow = '';
function popitup(url) {
    if (!newwindow.closed && newwindow.location) {
        newwindow.close();
        newwindow=window.open(url,'name'+Math.random(),'height=600,width=800');
    }
    else {
        newwindow=window.open(url,'name','height=600,width=800');
        if (!newwindow.opener) newwindow.opener = self;
    }
    return false;
}

Please note I used a new window name every time I close a window. Again in Safari one cannot reopen the same named window after closing it.

I also used following references which were helpful for me.

  • Javascript – Cross window scripting
  • about window.open() in safari
Share

Tags: Flex
Filed under General | 1 Comment »



One Response to “Getting through Popup Blockers with window.open() in Flex”



    Link Post Sunday 01/03 | Mr Sun Studios Says:
    Posted at: January 24, 2009 at 1:07 pm

    [...] Getting through Popup Blockers with window.open() in Flex by Xebia Blog [...]

    Reply


Leave a Reply

Click here to cancel reply.


Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India
  • Xebia Sweden

Categories

  • Java (311)
  • Agile (181)
  • General (136)
  • Scrum (67)
  • Architecture (64)
  • Testing (59)
  • Performance (46)
  • Middleware (56)
    • Deployment (38)
  • Xebia Labs (39)
  • SOA (31)
  • Podcast (31)
  • Project Management (28)
  • Tools (26)
  • Uncategorized (20)
  • lean architecture (20)
  • Quality Assurance (17)
  • Articles (13)
  • Requirements Management (13)
  • Virtualization (19)

Tag Cloud

    Flex lean architecture Architecture Scrum Scala Agile Frameworks Oracle XML Maven agile architectuur Spring Javascript Ajax ACT Hibernate TDD Xebia Moving to India Eclipse Groovy Grails Lean Java JPA SOA lean architectuur product owner JPA implementation patterns Concurrency Control

Archives

  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
Avatars by Sterling Adventures