Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question javascript function access question

    i have a site that uses multiple frames and html files for centering. is there a way to write a javascript function so that when a link is click it will open a page and then access a fuction on another page that changes 2 frames at once? i have a function written already but it only works when im on the page that the javascript is written in.

    im not very familiar with javascript and i have searched around a lot not able to find a specific answer to my question. any help is appreciated. thanks.

  • #2
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i read my post and it seems confusing so ill try to clear it up. my site has an opening page which has a couple links to different menu options. when an option is clicked a page is opened called index2.html. this page then has 3 frames left, center, and right. and within in center i have 3 more top, middle and bottom. then in middle is where i have 2 more frames, on the left is an html file with a pic in it and on the right i have a body.html file with a menu and the javascript code in it. so when a link is clicked from the opening page it opens up index2 and i need it to use the function that is in the the body.html file to change the left (picture frame) and the right body frame depending on the link they clicked on the opening page. is this possible?

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    why do you have to use frames? they're a big no-no. they have been since they first came out.

    you can achieve the same effect these days using layers and iframes or object tags.

  • #4
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i was used just using empty frames to center my site. like www.cecildreeme.com
    so it will be centered no matter what the persons screen resolution is. could i do that with layers an iframes?

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes it is possible. In your frameset, where you define your frames, you must ensure to give those frames unique names.

    That way you can refer to those frames by their names, for example:
    index.html:
    Code:
     <frameset rows="20%,80%"> 
      <frame src="file1.html" name="frame1">
      <frame src="file2.html" name="frame2">
     </frameset>
    
     window.top.frames["frame1"].functionName();
    So basically file1.html might have a function in it called functionName(). The window.top... line could be called in file2.html, so it's calling functionName() in file1.html.

    Now the important thing to note is that all files in all frames must exist on the same server/domain. You can't load up Google in one of your frames and try to call its functions as you will get an Access Denied error. If you get that right now trying to make your site work, then ensure that each file is on the same domain and if your links are not relative but absolute, that your links have the same domain reference (ie. be consistent: only use IP addresses or domain names, don't mix and match because that will give you some grief!)

    Hope that helps,
    Sadiq.

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was trying to figure out why anyone would bash frames.. so I Google'd it and came up with the following link:
    http://www.useit.com/alertbox/9612.html

    So now I sort of understand why frames can be bad... but I still like them!

    Any comments?

    Sadiq.

  • #7
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sad69 i tried using the window.top.frames thing but it's not working. this is the code im using in my opening page:

    function change2(name)
    {
    location = ("index2.htm");
    window.top.frames["_body"].go('name');
    }
    when a link is clicked that function is executed. And it goes to index2 but it doesn't run the go function located in the _body frame. i also have the frame named _body so i can't be that.
    this is the go function:

    function go(name)
    {
    parent._left.location= (name + "left.htm");
    _right.location= (name + ".htm");
    }

    the go function works when i click a link that is located in the _body frame.

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dunno why, but try changing top to parent and see how that works out..

    Sadiq.

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    function change2(name)
    {
    location = ("index2.htm");
    window.top.frames["_body"].go('name');
    }

    It does not work because index2.htm, which contains the nested frames one of which you were referencing, has not finished loading.

    Instead of using bunches of frames, why not use iframe and then put the links in the same page where the iframe is?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •