JS: openInNewWindow Breaks Parent Page

I encountered a very weird issue when trying to create a Dynamic Navigation Menu on APEX 5.0.4. I needed to be able to generate whether a URL could be specified to open within an iFrame on the homepage of the application, or to open up as if target=_blank had been enabled. Using a case statement it wasn’t too difficult to find out how to dynamically generate the link that did this. The “New Tab” link generated looks like this:

'javascript:apex.navigation.openInNewWindow(' || chr(39) || utl_url.unescape(LINK_TARGET) || chr(39) || ');'

Except Internet Explorer 11 had some different ideas.

On any modern browser whenever I generated and clicked on the “Open in New Tab” link, a new tab would open and both would work perfectly fine. On IE11 though, it would open the new tab which would function correctly but the parent page would break, showing only one thing: [object].

Thanks to some lucky Googling I was able to find an answer, and Maxime Tremblay also kindly added an explanation on why this issue occurs.

By appending ;void(0); to the end of the “New Tab” code it works, so now it looks like this:

'javascript:apex.navigation.openInNewWindow(' || chr(39) || utl_url.unescape(LINK_TARGET) || chr(39) || ');void(0);'

This is what Maxime had to say about the issue:

Hello Ross

 

We also stumbled on that some time ago for a dynamic navigation menu just like you did.

 

The cause is that the openInNewWindow JS function is returning an object

 

https://docs.oracle.com/database/apex-18.1/AEAPI/apex-navigation-namespace.htm#GUID-BD152481-5EC7-4BBD-A7A0-98BA043D3AB0

 

Returns the window object of the named window or null if for some reason the window isn’t opened.

 

and IE being IE is trying to display that object…

 

As you said appending void prevents the returning object.

 

What we ended up doing is this:

 

javascript:var win=apex.navigation.openInNewWindow(...);

 

The two works just as fine. Just be sure to comment that the void has a use because another dev could see this as useless code and could remove it.

 

Regards

 

Max

So hopefully if you encounter this problem you’ll either find this blog post or my post on the Oracle APEX forums because it plagued me for far too long and I got very lucky to find the solution.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s