-2

I need to make it so that when users visit a web page like example.com/news it automatically brings them to a different website like cnn.com without them having to click anything. It would be preferable if they would not even see the original web page and it would bring them directly to the other site (cnn.com in this case) I think I can use the onload event in html but I have little experience in javascript and don't know what code to use in order to accomplish this task. Thank you!I do not want to use jquery if possible.

  • 1
    Possible duplicate of [How can I make a redirect page using jQuery?](http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-using-jquery) – Aᴍɪʀ Dec 13 '15 at 06:16

2 Answers2

2

Just one line of code (inside script tags)

<script>
   window.location.href = "http://exampleurl.com";
</script>
Jack Guy
  • 8,346
  • 8
  • 55
  • 86
0

You would be better off using headers. Depends what server side scripting language you are using. For PHP you would have the following:

header('Location: http://www.example.com/');
Mat Taylor
  • 191
  • 10