在索引文件中使用js

编程入门 行业动态 更新时间:2024-10-11 15:15:29
本文介绍了在索引文件中使用js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

能否将javascript放在index.php的开头,以便它是在网页上加载的第一个代码? 香港专业教育学院尝试过,但是该网站根本无法加载.我需要使用此代码来找出用户是否单击了链接,以从移动网站上在完整站点上查看完整文章.

Can you put javascript at the beginning of the index.php so that it is the first code that loads on a webpage? Ive tried, however the website won''t load at all. I need to use this code to find out if the user is clicking a link to full an article on the full site from the mobile site.

if ( document.referrer.search('oursite')== 0 ) { include "index2.php"; } else { include "mobiledetection.php"; /* plus the other code already in the index file*/ }

index2.php是之前索引文件中的代码. 香港专业教育学院试图使用没有JavaScript的document.referrer函数,并在外部js中尝试它,但可以工作

The index2.php being the code that was in the index file before. Ive attempted to use the document.referrer function without javascript, and try it in an external js but either works

推荐答案

PHP. document.referrer是Javascript,include是PHP. 由于Javascript是在客户端上发生的,因此您需要显示一个包含Javascript代码的页面并重定向到另一个页面以获得所需的效果,或者在PHP中完成所有操作,然后可以使用include命令: It looks like you''re mixing up Javascript and PHP. document.referrer is Javascript and include is PHP. Since Javascript happens on the client, you would need to either display a page containing your Javascript code and redirect to another to get the effect you want, or do it all in PHP where you can use the include command: <?php // yes, this is how HTTP_REFERER is spelled if(isset(

_SERVER [' HTTP_REFERER']) && strpos( _SERVER['HTTP_REFERER']) && strpos(

_SERVER [' HTTP_REFERER'],' oursite')=== 0){ 包括" index2.php" ; } 其他 { 包括" mobiledetection.php" ; } ?> _SERVER['HTTP_REFERER'],'oursite') === 0) { include "index2.php"; } else { include "mobiledetection.php"; } ?>

您还应该注意,引荐来源网址不可靠-浏览器不必发送引荐来源网址,因此如果您不知道访问者来自何处,则应该决定该怎么做. 为了进行测试,您可以使用Web Developer FireFox插件禁用发送引荐来源信息的详细信息.

You should also note that the referrer is not reliable - the browser does not have to send it, so you should decide what to do if you don''t know where the visitor has come from. For testing, you can disable sending referrer details using the Web Developer FireFox add-on.

更多推荐

在索引文件中使用js

本文发布于:2023-10-11 17:27:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1482345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   文件   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!