Forum Moderators: open

Message Too Old, No Replies

It is possible to call one function into another in JavaScript?

         

Whopper

2:42 pm on Dec 20, 2022 (gmt 0)

Top Contributors Of The Month



How we can access a function defined in one.js in two.js?

I told them an answer using HTML, but they were looking for an answer that didn't involve linking via the HTML.

How is this possible?




[edited by: not2easy at 3:33 pm (utc) on Dec 20, 2022]
[edit reason] Please see TOS [webmasterworld.com] [/edit]

MichaelBluejay

1:31 pm on Dec 31, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm not sure what you're asking, but all functions defined anywhere are available from anywhere on the page. For example:

HTML
<script src=test1.js></script>
<script src=test2.js></script>
<script>window.onload=fire</script>

test1.js
function fire() {
callFunctionInOtherScript()
}

test2.js
function callFunctionInOtherScript() {
document.write('success')
}

robzilla

3:21 pm on Dec 31, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You'll need to make sure two.js is loaded after one.js.

Not sure what you mean by "an answer that didn't involve linking via the HTML".