Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: such a code available?

  1. #1
    Join Date
    Jul 2006
    Posts
    95
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default such a code available?

    I would like my index page to automatically go to another page after a specified amount of time but the URL remain the same as index.htm. May I know is there such a code available?

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    The first part could easily be done, but this?
    but the URL remain the same as index.htm
    I don't really understand why you would want to do that.
    - Mike

  3. #3
    Join Date
    Jul 2006
    Posts
    95
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default

    To prevent the easy access of the source code.

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Well, that can't be done, sorry to say. The url is there whether you like it or not. Hiding it doesn't change the fact that it is there, and most anyone could find it. Using frames is the closest thing to this, but HTML 4.01 Strict (most popular validator) doesn't allow it.
    - Mike

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    As for the timer, check this out:

    Code:
    <script type="text/css">
    var i = 0
    //couting variable
    var sec = 10
    //number of seconds to wait
    var target = "http://www.yourpage.com/"
    //the page that will be loaded
    onload=function timer() {
    i=i+1
    if (i>sec) {window.location.href=target}
    setTimeout("timer()",1000)
    }
    </script>
    - Mike

  6. #6
    Join Date
    Jul 2006
    Posts
    95
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default

    Many thanks for the code, mburt.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This should be done with a meta refresh:
    Code:
    <meta http-equiv="refresh" content="10;url=http://www.yourpage.com/">
    Perhaps with some Javascript as backup:
    Code:
    <script type="text/javascript">
    window.onload = function() {
      setTimeout(function() {
        window.location.href = "http://www.yourpage.com/";
      }, 10 * 1000);
    };
    And always with a normal link just in case:
    Code:
    Sorry, you should have been redirected <a href="http://www.yourpage.com/">here</a>
    Last edited by Twey; 08-24-2006 at 04:11 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2006
    Posts
    95
    Thanks
    21
    Thanked 0 Times in 0 Posts

    Default

    Many thanks to Twey for your kind input.

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    mburt: Does that code even work? Functions declared with function identifier(arguments) { shouldn't return a value.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    mburt: Does that code even work?
    It will work in many browsers. It does violate the specification, though.

    Functions declared with function identifier(arguments) { shouldn't return a value.
    I don't think you meant to phrase that statement the way you did. The problem with something like:

    Code:
    var funcRef = function funcName() {
        setTimeout('funcName();');
    };
    is that setTimeout evaluates strings in global scope. That is, all identifiers that appear in the string must be available through properties of the global object. The identifier in function expressions (funcName, above) should not be exposed by the interpreter outside the function body.

    Code:
    var funcRef = function funcName() {
        alert(typeof funcName);
    };
    
    alert(typeof funcName);
    should display 'undefined', whereas calling the function [funcRef()] would display 'function'.

    If one were to follow mburt's suggestion (there's no need though; Twey's is fine), the function (and assignment) should be rewritten:

    Code:
    function timer() {
        if (++i > sec) window.location.href = target;
        setTimeout('timer();', 1000);
    }
    this.onload = timer;
    Mike

Bookmarks

Posting Permissions

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