I need to make A Dynamic HTML Page to Redirect to A URL Using JavaScript.
As a beginner, i need your help...
What i want to do is to redirect to a url through a html page.
For example: suppose a page address is www.example.com/pages.html?http://yahoo.com/news so this pages.html page in this case will redirect a user to yahoo.com/news ....
I know how to do this with PHP but i cant understand how i should do it with javascript and HTML . any idea? Thanks
-
is that a query string? or is that the format of url?Ashirvad– Ashirvad2012-08-29 18:26:58 +00:00Commented Aug 29, 2012 at 18:26
-
location.href = location.href.split("?")[1];Krishna Kumar– Krishna Kumar2012-08-29 18:34:31 +00:00Commented Aug 29, 2012 at 18:34
Add a comment
|
3 Answers
This should do it:
function Redirect(){
var current = window.location.href;
var exclude = current.indexOf('?');
window.location = current.substr(exclude + 1);
}
setTimeout("Redirect()",5000);
3 Comments
blömpæ
thanks its OK now :) wonder is there any variables like
sleep(5); which is possible in php to set timers . can i do like this with javascript, so people will redirect to that url after 5 seconds! thanksTravis J
@itistg - edited to include a 5 second pause before redirection
blömpæ
thanks, its works perfectly now!! by the way i was trying with
setTimeout("countdown()", 5000) ..... :)