使用Javascript中的window.location打开PHP页面不起作用
如何从javascript函数打开php页面使用Javascript中的window.location打开PHP页面不起作用,javascript,window.location,location-href,Javascript,Window.location,Location Href,如何从javascript函数打开php页面 window.location=”http://www.google.com"; window.location.href=”http://www.google.com"; location.href=”http://www.google.com"; 他们都不工作。 甚至输入php.ini allow_url_fopen = on 我的方法有什么问题 window.location.href = "http://www.google.com";
window.location=”http://www.google.com";代码>
window.location.href=”http://www.google.com";代码>
location.href=”http://www.google.com";代码>
甚至输入php.ini
allow_url_fopen = on
我的方法有什么问题
window.location.href = "http://www.google.com";
这只会将用户重定向到谷歌
但是您不能在JS变量中加载页面,每个浏览器都有“跨域”限制(除非页面与您的JS文件和访问者位于同一个域中)。如果您将此javascript嵌入到标记中,它应该可以工作:
<script type="text/javascript">
window.location = "http://www.google.com";
</script>
window.location=”http://www.google.com";
但是,您不能在使用thsi javascript函数编写的页面中包含PHP脚本:它只会将浏览器重定向到google或您在window.location中设置的任何其他页面。可以使用PHP include()或require()函数在PHP页面中包含PHP脚本:
<?php
include('file.php');
?>
因此php.ini的allow\u url\u fopen行与此无关。允许或不允许为PHP的fopen函数提供url 这里您要做的是使用
window.location='/page.php'
将用户重定向到另一个页面
除非“打开”意味着在实际页面中加载,否则在本例中,请查看。您应该使用jQuery的
应该有用
我认为您的javascript代码包含一些错误,因此无法正常工作。您可以粘贴完整的代码吗?请提醒一些事情,并确保代码处于流动状态。
窗口。位置
是正确的方法。如果您正在iframe或FB应用程序中尝试,请尝试window.top.location
它们是否在-tags中?您是否使用框架?对于框架,您最终会收到一个跨域请求,该请求被一些网站(如谷歌)阻止。CORS问题只会在XHR中出现。在用户登录并知道其状态后,我想提醒用户进入不同的新页面。。。。使用google来避免我的站点不工作或找不到window.location=“../../member/en/member.php”;这就是我所需要的或window.location=“../../admin/en/admin.php”;在标题中列出一个函数。。。所有函数都有标记swindow.location=“../../member/en/member.php”;只要页面可以正常访问(例如,只需将地址写入地址栏,它就在地址栏中工作),那么您的window.location=“../../member/en/member.php”代码>应该可以工作。我会检查以确保该位置可以正常访问。完整代码:函数callmemberpage(){alert(“callmemberpage被调用”);window.location='../../member/en/member1.html';}忽略我所说的关于标题的内容。这是用于PHP header()函数的:P它仍然不工作吗?
window.location = "http://www.google.com";