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.

20 thoughts on “Opening URL in a new window

  1. 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”)?

  2. 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

  3. 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”

  4. Thanks Patrick, this has been very helpful. Unfortunately, I have found problems when using a relative URL, rather than a fully qualified URL. For example if I want to navigate to a page ‘f?p=…’ using this technique, it doesn’t work. I have to instead prepend the ‘http://my.site.com/f?p=…’

  5. For what it’s worth, I modified your approach and captured the onclick event and everything looks good…something like:
    #” onclick=”window.open(…..)

  6. Hey Patrick, do you know if it is possible to redirect to a page within the application and control the width and height of the popup window?

  7. Hi Leland,

    you can use

    javascript:html_PopUp(‘url’, ‘windowName’, 800, 600);

    as link target. html_PopUp is a function provided by APEX which opens a page in a popup.

    Regards
    Patrick

  8. Hi, I’m hoping someone can help me. In my URL Target property, I have:
    http://www.google.com/” target=”_blank

    It spawns the new window, but the URL is listed as
    javascript:redirect(‘http://www.google.com/
    and gives me the “Internet Explorer cannot display the webpage” error. What am I doing wrong?

    Thanks!

  9. hi,

    i found the error on code:

    javascript:html_PopUp(’url’, ‘windowName’, 800, 600);

    i change it to:

    javascript:html_PopUp(‘url’, ‘windowName’, 800, 600);

    its working . but i want to know how i can set the window position. please help

  10. If you are having errors on your opener page you may want to look at this info: http://jennifermadden.com/javascript/window1.html

    Specifically the section titled “The [object] oops”. I used the target on my button as “javascript: window.open(‘http://my_url.com’,’_blank’);” and kept getting the [object] text on my opener page – oops!

    I was not able to get the example Patrick shows to work – I also got the same problem Michelle posted. Using the info from the web site I listed took care of that: “javascript: void window.open(‘http://my_url.com’,’_blank’);”

  11. Hello all,

    I have a column link with an url like this:
    http://url/#MYCOLUMN#” target=”_blank – it works!

    but when i replace it with:
    javascript:html_PopUp(’http://url/#MYCOLUMN#’, ‘windowName’, 800, 600);

    NOTHING happens when I click on it!

    What’s wrong?

  12. Just overload the redirect javascript in the pages header

    For example:

    function redirect(url)
    {
    window.open (url, “newWindow”,”status=1,toolbar=1, width=400,height=300″);
    }

  13. Got the same problem as Michelle. Wayne’s solution did the trick for me, but instead of overloading the redirect function (which will cause all redirects on the page to open a the new window), I created my own new function in the page’s HTML header:

    function showhelp(url)
    {
    window.open (url, ‘Help’,status=1,toolbar=1, width=400,height=300);
    }

    I then called the function from the button’s URL target:

    javascript:showhelp(‘http://www.google.com’);

  14. Hi, none of the above solutions are working at our installation.

    I always get following error:
    ERR-1777: Page 200 provided no page to branch to.

    Is there any configuration problem?

  15. In the target URL Target box type in
    javascript:popupURL(‘url’)

    for example:
    javascript:popupURL(‘http://www.google.com’)

    Good Luck.

  16. I am new with Apex and like to open a blog column in a new window,
    I’ve created a page , configured a colum blog, but when I click in the link , it is opening in the same window.

    Thanks.

  17. This is happing only if the blob is jpg or gif , when the blob is pdf it is oppening in a new window.

    How can I open a new window for jpg also?

  18. Why doesn’t it work the same once deployed as it does when running it from the development environment?

    I have a report with a link that opens a PDF. In IE in development it opens the PDF with a full tool bar so I can use the back button and go back to my list to select another PDF. Once the app is deployed the window that’s opened does not have the back button and if I close the list it goes back to Portal page where I have to launch the application express app to bring the list back up.

  19. We have a reason for our production system that we disable the toolbar so that the users can’t use the back button for some applications. My application starts up from the same menu so the back button isn’t an option. What I want is for the column link to open the pdf in a new window and can’t figure that out.

    Thanks,
    Mike

Comments are closed.