PHP header和Javascript window.location有什么区别? [英] What is the difference between PHP header and Javascript window.location?

查看:120
本文介绍了PHP header和Javascript window.location有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当我教某人如何重定向他们的页面时,这是随机出现的。我真的不确定主要区别是什么......是否有理由相互使用一个?我猜如果你不用PHP编码,你将不得不使用Javascript window.location 重定向,但是你会使用 window.location 通过PHP 头文件如果您使用PHP进行开发?我觉得他们有非常相似的功能,但也许我错过了一些东西。

解决方案

浏览器会立即处理标题重定向,直到页面加载(或至少足以运行Javascript),Javascript重定向才会被执行。此外,它将是执行重定向的JavaScript引擎,而不是浏览器本身。



通过头进行操作会更好。 (稍微反正......)

So yeah this came to mind randomly when I was teaching someone how to redirect their page. I wasn't really sure what the main difference was... Is there a reason you would use one over the other? I guess if you are not coding in PHP, you would have to use the Javascript window.location to redirect but would you ever use window.location over PHP header if you were developing in PHP? I feel they have very similar functions but perhaps I am missing something.

解决方案

The browser will process the header redirect right away, whereas the Javascript redirect will not be executed until the page has loaded (or at least enough of it to run the Javascript). Also, it will be the Javascript engine executing the redirect instead of the browser itself.

Doing it via the header will perform better. (slightly anyway...)

这篇关于PHP header和Javascript window.location有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆