Calling functions in different documents

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Twinkletoes

    Calling functions in different documents

    Hello people, my first post here... *wave*

    I need to know how to call a function in a different document. At the
    moment I've tried onFocus but I'm kinda in over my depth. Perhaps if I tell
    you what I want to do you can give me the process and I'll go figure out the
    code?

    My site is divided into two frames, top frame for navigation, bottom frame
    for displaying content (called "top" and "main" respectively).

    "top" contains 6 images within 6 seperate anchors, that I use as buttons to
    switch between sections, the sections being displayed in "main". When the
    mouse is over an image, it changes because I use "OnMouseOve r", similarly
    for "OnMouseOut ".

    Here is where I get stuck. I want a different image to be displayed as the
    relevant button in "top" depending on which main section is loaded into
    "main".

    I was hoping to solve this by using "onLoad=" in each of the main pages for
    each section, that will call a function in "top.html" to cycle through the
    list of images changing the relevant image depending on the content of
    "main".

    I can see an inherent problem here, I have to make every page (could be
    hundreds! - nightmare) call this function.

    Is there any help you can offer please?

    Kind regards,
    Steve :)


  • Lasse Reichstein Nielsen

    #2
    Re: Calling functions in different documents

    "Twinkletoe s" <nojunk@nospam. noviagra> writes:
    [color=blue]
    > I can see an inherent problem here, I have to make every page (could be
    > hundreds! - nightmare) call this function.[/color]

    Lots of work, yes.
    [color=blue]
    > Is there any help you can offer please?[/color]

    How about changing the image when you click on the button?
    Clicking will initiate the loading of the main frame, so you can change
    the image of the button right away.

    This will *not* work if you follow a link in the main page to another
    section. If that is possible, you will need code on the page in the
    main frame to update the menu.


    Ok, if you are desperate, you can make the top frame check the
    location of the main frame every second, and then update the images
    accordingly.

    setInterval(fun ction(){testLoc ation(parent.fr ames['main'].location);},10 00);

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Twinkletoes

      #3
      Re: Calling functions in different documents

      In a flash of pure inspiration, Lasse Reichstein Nielsen declared:
      [color=blue]
      > "Twinkletoe s" <nojunk@nospam. noviagra> writes:[/color]
      [color=blue]
      > How about changing the image when you click on the button?
      > Clicking will initiate the loading of the main frame, so you can
      > change the image of the button right away.
      >
      > This will *not* work if you follow a link in the main page to another
      > section. If that is possible, you will need code on the page in the
      > main frame to update the menu.[/color]

      Ah, this sounds like the way to go.

      Thank you very much.
      Steve :)


      Comment

      • Twinkletoes

        #4
        Re: Calling functions in different documents

        In a flash of pure inspiration, Lasse Reichstein Nielsen declared:
        [color=blue]
        >[/color]
        setInterval(fun ction(){testLoc ation(parent.fr ames['main'].location);},10 00);

        I can't seem to be able to call my function in a page in a different frame.

        http://www.leicesterchurchmusic.org/index.html shows my frame definitions
        and the function GetPageName(), which works fine. From within this function
        I'm trying to call a function in 'top.html' that exists in the frame called
        'top'. I'm doing this:

        function GetPageName() {
        strFullPath = new String(parent.m ain.location);
        arrayJustFileNa me = strFullPath.spl it("/");
        strFileName = arrayJustFileNa me[arrayJustFileNa me.length-1];
        arrayName = strFileName.spl it("."); //0 element is just the name
        window.parent.t op.test(arrayNa me[0]);
        return arrayName[0];
        }

        http://www.leicesterchurchmusic.org/top.html contains the function test().
        Here it is:

        function test(page) {
        alert(page);
        }

        When this function exists in the same document it works fine, but not when I
        move it to another one. What am I doing wrong?

        Thanks,
        Seve :)


        Comment

        Working...