Home > Adding Application Components > Incorporating JavaScript in... > Incorporating JavaScript Fu...
Previous |
Next |
There are two primary places to include JavaScript functions:
In the HTML Header attribute of the page
In a .js file in the page template
See Also: "Text with JavaScript Escaped Single Quotes" for information about referencing a shortcut inside of a JavaScript literal string |
One way to include JavaScript into your application is to add it to the HTML Header attribute of the page. This is a good approach for functions that are very specific to a page and a convenient way to test a function before you include it in the .js
file.
You can add JavaScript functions to a page by simply entering the code into the HTML Header attribute of the Page Attributes page. In the following example, adding the code would make the test
function accessible from anywhere on the current page.
To add JavaScript code in the HTML Header attribute:
On the Workspace home page, click the Application Builder icon.
Select an application.
Select a page.
Under Page, click the Edit page attributes icon.
Scroll down to HTML Header.
Enter code into HTML Header and click Apply Changes.
For example, adding the following would test a function accessible from anywhere on the current page.
<script type="text/javascript"> function test(){ window.alert('This is a test.'); } </script>
In Oracle Application Express, you can reference a .js
file in the page template. This approach makes all the JavaScript in that file accessible to the application. This is the most efficient approach since a .js
file loads on the first page view of your application and is then cached by the browser.
The following demonstrates how to include a .js
file in the header section of a page template. Note the line script src=
that appears in bold.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>#TITLE#</title>
#HEAD#
<script src="http://myserver.myport/my_images/custom.js" type="text/javascript"></script>
</head>
<body #ONLOAD#>#FORM_OPEN#