4

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

2
  • is that a query string? or is that the format of url? Commented Aug 29, 2012 at 18:26
  • location.href = location.href.split("?")[1]; Commented Aug 29, 2012 at 18:34

3 Answers 3

2

This should do it:

 function Redirect(){
  var current = window.location.href;
  var exclude = current.indexOf('?');
  window.location = current.substr(exclude + 1);
 }
 setTimeout("Redirect()",5000);
Sign up to request clarification or add additional context in comments.

3 Comments

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! thanks
@itistg - edited to include a 5 second pause before redirection
thanks, its works perfectly now!! by the way i was trying with setTimeout("countdown()", 5000) ..... :)
0

You can use window.location.href="new-url.html"; to go to a URL with JavaScript.

To parse the URL, use var theURL=window.location.href.split("?")[1];

Comments

0
location.href = location.href.split("?")[1];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.