duangutang3940 2015-09-28 07:40
浏览 76
已采纳

如果重定向来自特定网址,则调用javascript函数

so this is my question - I have a redirect in my .htaccess file, which works perfectly. But now I need to call a js-function on the index page IF the redirect comes from /video. Is this possible? I have spend quite a long time on trying to figure this out - there is no code examples yet, so right now it is theoretical.
PS - I am using wordpress, so I've just added this to the general .htaccess - Redirect 301 /video / I would love to hear your inputs and various methods of achieving this.

EDIT So I will post the updated tried out methods here - so far we got this -

<?php $redirectedFrom = $_SERVER['HTTP_REFERER'];
if(isset($redirectedFrom)): ?> 
<script type="text/javascript"> 
    console.log("does the console work"+ "<?php echo $redirectedFrom ?>"); 
</script> <?php endif ?> 

This would work magically, if the redirect comes from a click link to the index (ie. menues etc.) but when I just write /video in the URL, it seems like the HTTP_REFERER is not being set, and herby not accessing the IF. So do any of you have a fix for setting the referer, or some other solution?

  • 写回答

1条回答 默认 最新

  • dongpi0658 2015-09-28 07:48
    关注

    You can check for the value of :

    $_SERVER['HTTP_REFERER'] 
    

    It should contain url of previous page so you can detect your page from PHP and print something into HTML and later check with JS for printed value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真