Skip to Main Content

Prepare_url & get_url

Note: Since Apex 20.1, the apex_page.get_url function DOES include the p_plain_url parameter, as in my new function detailed below. Somebody at Oracle may have read this page a while back... :-)
So this information is still valid, but only up till Apex 19.2.


Newer versions of Apex provide two functions to generate URLs: apex_page.get_url & apex_page.prepare_url.

The oracle documentation gives this example:
This query uses APEX_PAGE.GET_URL and its alternative APEX_UTIL.PREPARE_URL to produce two identical URLs. However, when using the apex_page.get_url on modal dialogs, you may run into a problem. The automatically generated JavaScript code to close a modal dialog may not be what you want, e.g. if you want the URL to open in a new window or tab:
Instead of the intended URL: "f?p=100:1234:12782432712506::NO::P100_ID:123" target="_blank">Link</a>
You will get this URL: "javascript:apex.navigation.dialog.close(true,'f?p=100:1234:12782432712506::NO::P100_ID:123');" target="_blank">Link</a>
Strangely enough this does not always happen on first page load; in those cases it loads with the intended URL but after a refresh of the page you do get the javascript version.

The prepare_url function has a p_plain_url parameter, which is just what we need to force the issue here. The description for this parameter: "Exclude any of the generated JavaScript code to close a modal dialog, if applicable. By default, if this function is called from a modal dialog, JavaScript code to close the modal dialog is included in the generated URL.".

In the package below I created a hybrid of the two functions. If you call this function with p_plain_url = true, this always returns a "non-javascript" URL.

A quick and dirty CSS fix is also possible. You can add an attribute (in this example data-apex-js-url="N") to the <a> tags that need fixing, and then replace the "junk" added by Apex using javascript like this:

Apex URL in Apex

I always have to look up the quick-and-dirty URL format for links to pages in this application, so I thought I'd put it here for easy reference. For example:

Code

Package

Package
Name
Source

Package Body

Package Body
Name
Source