简体   繁体   中英

how to call javascript function of one jsp from another jsp function

I have hello() javascript fuction in file1.jsp. I want to call hello() by file2.jsp. file1.jsp has

<html>
<script>
function hello()
{
...
}
</script>
</html>

I want to call this hello() function from file2.jsp

Perform the steps below:

Move the script in page1.jsp file to a new JavaScript file eg main.js file and place the file in new folder eg js inside your WebContent folder.

Link main.js in page1.jsp file by putting below link in the section:

/js/main.js"> Do the same in page2.jsp file.

This way, same javascript code will be available for use in both page1.jsp and page2.jsp files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM