views:

54

answers:

2

hello,

I have a

<a href="my_redirect_page.php?link=mylink">my_text</a> 

link on my page, and the following line in my_redirect_page.php:

header("Location: ".$mylink); 

but after the redirection, if I click on back in my browser, the "my_text" for the link does not appear as visited (in purple, instead of blue). How do I work around this? Is there a way to change the visited property in php or javascript?

Thanks,

Dave

A: 

I'm not sure this is possible, unless you change the way your redirects are done.

[This question][1] is basically a duplicate of yours, and the consensus was that none of the browsers allow you to set pseudo-classes (like :visited).

The easiest way to simulate it for the user is to set a CSS class which colours the link to look the same as a browser default or CSS-style visited link, which you can easily do in your view layer or by adding the class using javascript if the link appears in window.history.

You may also be able to push elements onto the window.history array, and have them appear in the browser history (and hence be given the :visited pseudoclass), but I'm not sure if that would work. Worth a try though.

cam8001
+1  A: 

Not a terrific solution, but, in my_redirect_page.php:

<html>
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh" content="0; url=<?php echo $_GET['link']; ?>">
</head>
<body>
Redirecting to <?php echo html_entities( $_GET['link'] ); ?>.<br>
If you are not redirected, <a href="<?php echo $_GET['link']; ?>">click here</a>.
</body>
</html>

Or something like that - the Page should load (thereby entering into the browser history) and then, with a delay of 0, load the targeted URL. Should, for some reason, the redirect fail, the user will see a page containing a link to the targeted URL.

Lucanos