在js中php的头位置的最佳替换是什么?

时间:2016-01-27 21:16:31

标签: javascript php jquery

php头位置函数的等价物是什么

<?php 
header("location:somepage.php");
?>
在JavaScript中

? javascript是否有像header函数一样的东西?如果是,那是什么?

5 个答案:

答案 0 :(得分:5)

等效的javascript是;

window.location.href = "somepage.php"

更多信息:http://www.tutorialspoint.com/javascript/javascript_page_redirect.htm

答案 1 :(得分:1)

你也可以使用meta标签立即将用户重定向到另一个页面,不需要javascript:

<html>    
  <head>      
    <title>Your Title</title>      
    <meta http-equiv="refresh" content="0;URL='http://example.whatever.com/'" /> 
  </head>    
  <body> 
      <!-- NO CONTENT -->
  </body>  
</html>  

这是客户端操作,而不是服务器重定向。

答案 2 :(得分:0)

用于重定向的Javascript:

window.location="http://www.example.com";

更多信息:http://www.tutorialspoint.com/javascript/javascript_page_redirect.htm

答案 3 :(得分:0)

Javascript在您的浏览器中执行,因此它将无法完成与请求具有重定向的php时所发生的完全相同的操作。如果你想要的只是访问另一个页面而没有向服务器发出请求,这就足够了:

window.location.href = "somepage.php"

答案 4 :(得分:0)

在Javascript中,与标题等价的是:

index.html(或index.php)

merge

请记住,文件example.php必须位于本地服务器的目录中(如果使用XAMPP或WAMPP)。