Hi,
I use a pass-through link tracking page on my site. If a user clicks on a link on my site that takes them to http://www.anysite.com, the link actually calls my passurl.php page with a GET variable of the URL ([url]http://www.anysite.com)[/url]. The passurl.php page updates a link click counter in my database and then passes the user to the anysite.com site using a header command.
When using my site, visitors are likely to click on several links that take them to external sites. I use the html target="_anytag" to make sure subsequent links open in the same window so the user doesn't have 10's or 100's of open windows after visiting my site.
The issue that I face is that I can't seem to force focus on the link windows when I use my passurl.php pass-through page. I'm using a self.focus javascript command on my passurl.php page with the hopes of forcing focus on this page before passing the user to the link page with the header command. The header command seems to get in the way for if I remove it, the passurl.php page is always opened in an existing browser window and always gets focus.
Here is my code:
...reference_links.php (reference links that users will click)
// Following test is used to determine which _target= tag to use. For purposes of this example, assume $target equals "msb_site".
$row_rs_link['LABEL'] == "Book" ? $target = "msb_book" : $target = "msb_site" ;
// This line will output the link to the page. For purposes of this example, assume ?type = "link", &id = 1, &url = http://www.anysite.com and $row_rs_link[CAPTION] is "Anysite.com provides you with a searchable list of mortgage providers"
echo "<td><a href='passURL.php?type=link&id=$row_rs_link[ID]&url=$url' target=$target >$row_rs_link[CAPTION]</a></td>" ;
Once the user clicks the link, the passURL.php page opens and has the following code (I've removed some stuff for readibility)...
<!-- javascript function to set focus to window. This works unless I use the header command below - which I seemingly have to since I don't know of another way to pass the user to the destination link. I'm not comfortable using javascript to perform this task due to issues with some people turning javascript off. -->
<script language="javascript">self.focus();</script>
<?php
if ( isset($_GET['type']) ) {
$type = $_GET['type'] ;
// database calls to update click tracking table; left out for brevity
// prepare sql statement
// run sql statement
// decode the url
$url = urldecode($_GET['url']) ;
// And here's where I pass the user to the intended destination. If the window
// already exists, the url is updated; however, the page remains in the background.
header("Location: $url", false);
}
?>
Hopefully this mess all makes sense. Interestingly enough, if the link is to www.amazon.com, that window always gets focus, regardless of my code. So that leads me to believe there's a way to do this even when using the php header command.
Any thoughts would be greatly appreciated.
Thanks for your help.