Click to See Complete Forum and Search --> : calling functions from a JS include


laces_out
01-30-2003, 01:46 PM
I'm trying to reference a function that's defined in a Javascript include(i.e. <script language="Javascript" src="mystuff.js">) The include seems to be working, since I can put alerts in there and they pop up, but I can't seem to reference functions that are inside the include. I'm guessing this is some kind of scope issue. (I can reference the functions from inside the include itself, but not the outer document) Thanks.

gil davis
01-30-2003, 01:48 PM
Post a link to the page, or zip it all up and attach it to your next post.

laces_out
01-30-2003, 03:10 PM
OK, I found out what's causing the problem. There's a <BASE TARGET="Main"> tag in there, where main is a different frame. If I take that out it finds the function. However, I need to leave that in, so how do I refer toe a function thats not in that other frame?

gil davis
01-30-2003, 03:15 PM
Post a link to the page, or zip it all up and attach it to your next post.

laces_out
01-30-2003, 03:33 PM
Originally posted by gil davis
Post a link to the page, or zip it all up and attach it to your next post.

I understood perfectly. I can't post the code on here because some of it is proprietary. I've been trying to create a minimal example to reproduce the behaviour, but haven't been able to yet. Is the question in my second post not clear?

laces_out
01-30-2003, 03:49 PM
I was able to put together a minimal example of what the existing code does. The lefthand frame has a javascript include that includes the function test_func(). Clicking the link calls that function. If the <base target="right"> tag is in, Javascript can't find the function. I hope this illustrates the problem sufficiently.

http://www.cfrap.org/frametest/frame.html

gil davis
01-31-2003, 06:23 AM
<a href="Javascript:top.left.test_func()">Call function</a>

BTW, the preferred method would be to use the onclick to envoke the function. That way clicking the link won't send the browser to the top of the page.

<a href="#" onclick="top.left.test_func();return false">Call function</a>

laces_out
01-31-2003, 07:04 AM
Perfect. Thank you.