Inside Oracle APEX by Patrick Wolf

Opening URL in a new window

You want to create a button or a navigation list entry where you want to open an URL in a new browser window?

With plain HTML you would normally just write
<a href="http://url/" target="_blank">

but how to specify the target="_blank" in Oracle APEX, where you just have the property "URL Target" which just allows you to enter the URL?

Sure you could use some Javascript code to open a new window or something similar. Sounds a little bit complicated, or? There must be an easier way!

There is!

You can use the same technique as for SQL injection. Just write
http://url/" target="_blank

into the "URL Target" property. APEX will add the closing quote after _blank for you, because it thinks the URL ends there. That way APEX generates a valid a href with a target for you.

For buttons where APEX generates a javascript:redirect('yoururl') you have to use.
javascript:window.document.location.href='http://yoururl/'" target="_blank


Labels: , ,

12 Comments:

  • I might be mistaken but don't all APEX URL Target sections also have a "Link Attributes" box where you can specify exactly this (target="_blank")?

    By Anonymous Anonymous, at 14 May, 2007 01:26  

  • Hi,

    only a report column has the "Link Attributes" property. Buttons, List Entries, ... don't have this property, they just have "URL Target" and that's it. At least in my APEX 3.0 development environment.

    Patrick

    By Blogger Patrick Wolf, at 14 May, 2007 08:43  

  • Seems simple enough, but... I tried to convert a button that opens a url fine in the same window, but after changing the url target as stated the result was page not found error and the address shown was ".../pls/apex/wwv_flow.accept"

    By Anonymous Anonymous, at 19 November, 2007 02:06  

  • Have you set the property "Target is a" to URL?

    In the "Page Definition" view, does your button show "Redirect To http://xxx" next to it?

    Patrick

    By Blogger Patrick Wolf, at 19 November, 2007 09:22  

  • Patrick,

    When I set the target as URL and specify the URL, Apex uses code similar to..

    javascript:redirect('url');

    and so the "target injection" didn't work!! Have you got any other way of handling this please? It's silly that Apex hasn't got a direct way of specifying the target!!

    By Blogger Kannan, at 20 February, 2008 01:52  

  • Patrick

    I've quickly knocked up a solution to this problem and it is available at

    http://apex.oracle.com/pls/otn/f?p=46305:3

    I know, the one that I did after I posted my question to you was not a generic solution. But a workable solution.

    Can you please check and guide if there is any other generic way?

    Thanks
    Kannan

    By Blogger Kannan, at 20 February, 2008 03:23  

  • Hi Kannan,

    just use

    javascript:window.document.location.href='http://test.com/'" target="_blank

    instead. At least it worked for me.
    Patrick

    By Blogger Patrick Wolf, at 20 February, 2008 08:28  

  • Patrick

    It did work for me too! Thanks.

    I still got to learn a lot in Javascripts!!

    Did you get a chance to look at the "Improve Popup LOVs Look-and-Feel" on the blog page? http://kannankumara.blogspot.com/2008/02/improve-your-popup-lovs-look-and-feel.html

    I'm wondering if there is any other easy way. Sorry to trouble you, but just curious.

    Kannan

    By Blogger Kannan, at 21 February, 2008 18:19  

  • Patrick,

    I tried your suggestion for buttons where APEX generates a javascript:redirect and this works fine except when the URL contains #. Here is an example: http://www.opsi.gov.uk/SI/si1999/19990437.htm#end
    In this case I get a page not found. Can you help?

    Thanks.
    Donald.

    By Anonymous donald.gray@baesystems.com, at 03 July, 2008 14:40  

  • There are attributes that could be used for this in the definition of the list item or button but these need to be part of the template used to render the item. Many out of the box themes don't include every possible replacement string (and some of them I just can't figure out like #TEXT_ESC_SC#).

    By Anonymous Greg J, at 05 September, 2008 21:08  

  • Hi Greg,

    #TEXT_ESC_SC# is the escaped version of #TEXT# -> no Javascript/HTML code is executed/rendered if the text contains it.

    Patrick

    By Blogger Patrick Wolf, at 06 September, 2008 19:08  

  • How would you do this to link to a page IN the application?

    By Anonymous Anonymous, at 15 October, 2008 20:38  

Post a Comment

<< Home