echo Javascript window.location.href 不起作用
echo Javascript window.location.href not working
我有一个函数,它回显javascript导航到不同的页面。导航发生时,
echo 'window.location.href="'.$url.'";';
不起作用,只是将其打印在屏幕上。
"window.location.href="./index.php";
我以这种方式使用我的函数:redirect("./index.php");
我的php函数如下
function redirect($url)
{
if (!headers_sent())
{
header('Location: '.$url);
exit;
}
else
{
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>'; exit;
}
}
您的浏览器将响应视为纯文本。
在回复前面加上Content-Type: text/html'
n,并将您的内容包装在 <html></html>
标记中。
试试这种方式。
<?php
$yourURL="http://www.stackoverflow.com";
echo ("<script>location.href='$yourURL'</script>");
?>
为什么不只使用输出缓冲,而根本不需要处理JavaScript或元重定向?
<?php
// Top of your page
ob_start();
// Code goes here
// Redirect
if ($redirect_is_necessary)
{
header('Location: '.$url);
exit;
}
// Rest of page goes here
// Bottom of page
ob_end_flush();
?>
相关文章:
- Javascript-将变量传递给php页面,window.location.href不起作用
- 使用 Div 标签的 location.href 属性时,Eval 不起作用
- 当在 img 标签中提到类时,Href 不起作用
- 输入框上的 Href 不起作用
- JavaScript window.location.href 不起作用
- window.location.href 不起作用,无法重定向
- 幻灯片 href 不起作用
- 加载函数对 href 不起作用
- window.location.href 不起作用
- javascript document.getElementById 将 .value 更改为 .href 不起作用
- echo Javascript window.location.href 不起作用
- (jQuery)多拆分自动href不起作用
- 点击工作时 href 不起作用
- location.href不起作用
- 正在将类添加到此href.不起作用
- jQuery attr("href")不起作用
- Window.location.href '不起作用
- Jquery focus()和blur()对我的href不起作用.为什么
- Javascript更改.href不起作用
- d3js:`xlink:href`不起作用