/    Sign up×
Community /Pin to ProfileBookmark

Loading Script function into another Page???

It is even possible to load a script function to another page (another frame in my case)? Any help would be great, thanks.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@TageNov 12.2004 — I think you can call functions from another frame, but I don't think you can affect another frame with functions from a different frame. To call the function try something like...(and I'm not sure about this, but it's a start)parent.frameName.functionName();Tage
Copy linkTweet thisAlerts:
@Stonehenge81authorNov 12.2004 — Well I tried that command [parent.top.isWorking();] where top is the frame name and isWorking() is just a function that returns a alert window with some value.

Now the problem I got was two cases:

If I loaded the javascript call <SCRIPT SRC="script.js"> within that frame I'm calling from, I seems to just be calling that script itself, not the other script that is running on top.

If I remove the script within the, I get a error that I guess pretty much says the method doesn't exist.

Any other suggestion, please let me know, thanks much
Copy linkTweet thisAlerts:
@TageNov 12.2004 — I don't know why it's not working, I just made a simple example...maybe you can work with it. I have attached it as a zip file.

Tage

Edit: errr, let me try that again, I did the example wrong

Edit 2: okay, try this example instead...not much different tho
Copy linkTweet thisAlerts:
@TageNov 12.2004 — wasn't allowed to upload something in an edit after deleting first attachment -.-

[upl-file uuid=e23281c3-542c-492a-9862-69e64c48fec9 size=591B]frame.zip[/upl-file]
Copy linkTweet thisAlerts:
@Stonehenge81authorNov 12.2004 — It seems when I try the same thing it works.. But, I can't get current values that are in the other from when I make the call. DO you know what I might be doing wrong, if anything? Or is that just the nature of the function call?
Copy linkTweet thisAlerts:
@TageNov 12.2004 — Are you trying to get a variable's information from another frame and use it in a different one? [color=silver]That may not be possible with javascript. It may be viewed as a security issue and is not allowed. =| I could be wrong though.[/color]

Tage

Edit: Actually I just tried it and it worked, why don't you post your code down? or send me a zip file

Edit 2: I've got to log, I'll check your post later, hopefully someone can help you out in the meantime though
Copy linkTweet thisAlerts:
@Stonehenge81authorNov 12.2004 — 

Here is what i'm doing with your code Tage....
---------------------


index.html:

<html>

<frameset rows="50%, 50%">

<frame src="frame1.html" name="frame1">

<frame src="frame2.html" name="frame2">

</frameset>

</html>
------------------


frame2:

<html>

<head>

<script type="text/javascript">

<!--

counter=0;

function runCounter()

{

for (i=0; i<100; i++)

counter++;

alert(counter);

}

function getCounter()

{

alert(counter);

}

//-->

</script>

<body onLoad="runCounter()">

frame2

</body>

</html>
-------------------


frame1:

<html>

<SCRIPT LANGUAGE="javascript">

function run()

{

parent.frame2.getCounter();

}

</SCRIPT>

<body onLoad="run()">

frame1

</body>

</html>
--------------------



So basically... Frame 1 runs itself once, giving counter 100 and sending an alert of it.

THEN Frame 2 calls a function in Frame 1 to get the status of counter, which SHOULD be 100, but instead is 0 and gives an alert of it

I think you might be right, but if you or anyone else has any other suggestions, please let me know, thanks much!

The only reason I'm going through all this is to make my life a lot easier and keep from having do to a lot of repetative code, which has been the downside of using frames, but that again is easier for me to implament'ish.
Copy linkTweet thisAlerts:
@TageNov 12.2004 — 

From your example, it looks like you flipped frame1 and frame2 coding, but left the frame names and SRCs the same.
---------------------


index.html:

<html>

<frameset rows="50%, 50%">

<frame src="frame1.html" name="frame1">

<frame src="frame2.html" name="frame2">

</frameset>

</html>
------------------


frame1:

<html>

<head>

<script type="text/javascript">

<!--

counter=0;

function runCounter()

{

for (i=0; i<100; i++)

counter++;

alert(counter);

}

function getCounter()

{

alert(counter);

}

//-->

</script>

<body onLoad="runCounter()">

[color=red]frame2[/color]

</body>

</html>
-------------------


frame2:

<html>

<SCRIPT LANGUAGE="javascript">

function run()

{

parent.[color=red]frame2[/color].getCounter();

}

</SCRIPT>

<body onLoad="run()">

[color=red]frame1[/color]

</body>

</html>
--------------------



It kind of looks like the frame2 is referring to itself in your code.
Copy linkTweet thisAlerts:
@Stonehenge81authorNov 12.2004 — Well I fixed my last reply sorry. Tend to do that sometimes. Anywho, actually Tages codes works and it does work on another frames active script, but right now I have problems with my own script. Once I am done documenting my script I'll see if I can upload it here so someone can try to help me with what I'm trying to do
Copy linkTweet thisAlerts:
@Stonehenge81authorNov 12.2004 — MY gosh it works!!! WOo hoo!!! THanks a lot Tage...

What happened in my code was that I'm guessing that I was using a reserved word for my frame NAME="top". I changed it to topFrame and it works just find and it calls all whatever active script in another page just fine as well!! I'll still load my script and what exactly I'm doning once I finish with it. Thanks again!
×

Success!

Help @Stonehenge81 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...