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?
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?
The first part could easily be done, but this?
I don't really understand why you would want to do that.but the URL remain the same as index.htm
- Mike
To prevent the easy access of the source code.![]()
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
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
Many thanks for the code, mburt.
This should be done with a meta refresh:Perhaps with some Javascript as backup:Code:<meta http-equiv="refresh" content="10;url=http://www.yourpage.com/">And always with a normal link just in case:Code:<script type="text/javascript"> window.onload = function() { setTimeout(function() { window.location.href = "http://www.yourpage.com/"; }, 10 * 1000); };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!
Many thanks to Twey for your kind input.
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!
It will work in many browsers. It does violate the specification, though.Originally Posted by Twey
I don't think you meant to phrase that statement the way you did. The problem with something like:Functions declared with function identifier(arguments) { shouldn't return a value.
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() { setTimeout('funcName();'); };
should display 'undefined', whereas calling the function [funcRef()] would display 'function'.Code:var funcRef = function funcName() { alert(typeof funcName); }; alert(typeof funcName);
If one were to follow mburt's suggestion (there's no need though; Twey's is fine), the function (and assignment) should be rewritten:
MikeCode:function timer() { if (++i > sec) window.location.href = target; setTimeout('timer();', 1000); } this.onload = timer;
Bookmarks