Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Junior Member
    Join Date
    Nov 2003
    Location
    MI
    Posts
    5
    Member #
    3857
    OK... I am new to this forum and if someone already posted a question like this, I am sorry but...

    I have a problem where I am using the location.hash command within a javascript on page to automatically jump to a certain section of the page depending on the date/time. now... the problem is not with the jumping... that works fine... the problem is that when I put the scripted page in an iFrame, it scrolls the main page (the one that has the iFrame code on it) to the bottom. Well... that would be fine but I dont want my visitors to see the bottom of my web page before the top. any ideas on how to fix something like this? I have tried changing focus on the script page but that effected the main page also. I am running out of ideas.


    Also, on a side note... has anyone ran accross a problem where if you use a .js file to run a HTML form it dropps the referring URL information in IE? just a thought

  2.  

  3. #2
    Junior Member
    Join Date
    Nov 2003
    Location
    MI
    Posts
    5
    Member #
    3857
    anybody?

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Don't bump your post.

    The answer is not to use window.location.hash explicitly because it will reference the window in which the script is written.

    Instead, reference the window element of the iframe, like so:
    Code:
    <script>
    function myScript() {
        var iFrameWindow = document.getElementById("myFrame");
        iFrameWindow.window.location.hash();
    }
    </script>
    Make sure you only execute your script after the iframe is loaded using the body onload:
    Code:
    <body onload="myScript()">
    And here's your iframe (with the id set)
    Code:
    <iframe id="myFrame" src="whatever.htm">

  5. #4
    Junior Member
    Join Date
    Nov 2003
    Location
    MI
    Posts
    5
    Member #
    3857
    Sorry about the bumping... but it did not help... it seems to do nothing.

  6. #5
    Junior Member
    Join Date
    Nov 2003
    Location
    MI
    Posts
    5
    Member #
    3857
    actually I found out why it was doing nothing (there was 2 onload statements in the body tag) but now it is saying that window.location is null or not an object.

    Thanks BTW for the help

  7. #6
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Yup. If you want more help, post your full script.

  8. #7
    Junior Member
    Join Date
    Nov 2003
    Location
    MI
    Posts
    5
    Member #
    3857
    Well... right now I have it set where if it is in a frame it will ignore the location.hash. it is on a calander page. here is the script on the script page.

    <script LANGUAGE="JavaScript" TYPE="TEXT/JAVASCRIPT">
    // Array ofmonth Names
    var monthNames = new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December")
    var now = new Date()

    thisYear = now.getYear()
    if(thisYear < 1900) {thisYear += 1900} // corrections if Y2K display problem

    var gotoMonth = (monthNames[now.getMonth()] + " " + thisYear)

    var mySite = self.location
    var inFramed = top.location

    if(mySite == inFramed){
    location.hash = (gotoMonth)
    }


    </script>


    The iFramed page is:

    <script LANGUAGE="JavaScript" TYPE="TEXT/JAVASCRIPT">
    function frameDateSet();{
    // Array ofmonth Names
    var monthNames = new Array("January","February","March","April","May"," June","July","August","September","October","Novem ber","December")
    var now = new Date()

    thisYear = now.getYear()
    if(thisYear < 1900) {thisYear += 1900} // corrections if Y2K display problem

    var gotoMonth = (monthNames[now.getMonth()] + " " + thisYear)

    var myFrame = document.getElementById("calFrame")
    myFrame.window.location.hash = (gotoMonth)
    }
    </script>

    .
    .
    and the i Frame code looks like

    <iframe name="calFrame" src="calendar2003.htm" width="100%" height="515" align="center">

    Your browser does not support inline frames or is currently configured not to display inline frames.</iframe>

    is there anything else you need (BTW, yest the body tag onLoad is in it was just way to long and complicated with junk to post)

    Thanks again


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:51 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com