PDA

View Full Version : Accessing script on other page


Lazaroth
05-02-2003, 05:43 PM
Is it possible to access a script on different pages...

///////////////////

Page1.htm

<a onclick="access_script()">access</a>

///////////////////

Page2.htm

<script>

function access_script()
{
alert('hello');
}

</script>

sage45
05-02-2003, 06:42 PM
One of two ways... First way is to use an external script... However the way that you are specifying would require using the search method in javascript...

http://www.javascriptkit.com/javatutors/send1.shtml

HTH,

-sage-

requestcode
05-02-2003, 06:42 PM
If page1.htm and page2.htm are in a framed page then you can access the this way:
parent.frame_name.function_name()

Other than that you could place the script in an external file and reference it from the page like this:
<script language="JavaScript" src="myscript.js">
</script>

Then myscript.js would look like this:
function myfunc()
{
alert("Hi!")
}

Notice in myscript.js you don't see any <script> tags? You don't want them in there.