Skip to Main Content

Prepare_url & get_url

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.
  SELECT APEX_PAGE.GET_URL (
            p_page   => 1,
            p_items  => 'P1_X,P1_Y',
            p_values => 'somevalue,othervalue' ) f_url_1,
         APEX_UTIL.PREPARE_URL('f?p=25384:1:3239220584193::::P1_X,P1_Y:somevalue,othervalue')
     FROM DUAL
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::::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.

Code

Package

Package
Name
Source

Package Body

Package Body
Name
Source