简体   繁体   English

Javascript 与 php header 重定向

[英]Javascript with php header redirect

I'm working on a project that uses a <? header('Location: http://url.com '); ?>我正在开发一个使用<? header('Location: http://url.com '); ?> <? header('Location: http://url.com '); ?> <? header('Location: http://url.com '); ?> for redirects, and I'm very pleased with it because of the speed and the fact that it doesn't flash some intermediary URL in the address bar before redirecting. <? header('Location: http://url.com '); ?>用于重定向,我对它非常满意,因为它速度快,而且重定向前地址栏中没有 flash 一些中介 URL。 However, I now need to call my tracking software via a piece of Javascript like so:但是,我现在需要通过 Javascript 调用我的跟踪软件,如下所示:

<script type="text/javascript" src="MYSCRIPT"></script>

Is there any way to get the best of both words?有什么办法可以同时兼顾这两个词吗? Ie call my tracking software via the javascript and still use the php redirect?即通过 javascript 调用我的跟踪软件,仍然使用 php 重定向? Or will I have to switch to a JS window.location redirect if I want to call this script?或者如果我想调用这个脚本,我是否必须切换到 JS window.location重定向?

Thanks!谢谢!

You will either have to write the JavaScript code for your tracking in PHP and execute it before the redirect, or have a page with one of those 'you are being redirected' if you want to use Javascript.您必须在 PHP 中为您的跟踪编写 JavaScript 代码并在重定向之前执行它,或者如果您想使用 Z9E13B69D1D2DA927102ACAAAF771,则必须有一个带有“您正在被重定向”的页面。

The problem is that you cannot modify the header information after it has been sent.问题是header信息发送后无法修改。 ie you can't have anything after header('Location:');即在 header('Location:'); 之后你不能有任何东西。 redirect.重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM