call a javascript function, if the redirect comes from specific url

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 –

Read More
<?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?

Related posts

1 comment

  1. 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.

Comments are closed.