View Full Version : not exactly response.redirect

11-04-2003, 02:00 PM
I am having a trouble.
I am writing ststistics code, in order to count number of hits to a list of links in our site.
All pages r asp.

The list of links is in asp page which is displayed in one of the frames.
I'd like that when a user presses a link, the statistics database will be updated, and then I'd like the target of that link (a site) to be opened in a NEW WINDOW.

I tried calling the counting page in the new window and then opening the site, but then the user sees a blank page (with the counting page file name in the title bar), and then it is replaced with the linked site.

Basically what I need is that once link is clicked, the database of statistics will be updated and that the user will only see the site in a new window, and not a blank page even for 1 sec.
I have the counting page working great, it can also be just a sub in another asp page.

I have some q that may help me solve it:

1. Is it possible to response.redirect to a site in a new window, and also defining windows properties?This way I can redirect from the counting page. Will the counting page will replace the curent frame?

2.Is it possible to call a function written in vbscript inside asp tags, from javascript or href? (< href="vb function name">kjkj) ?
This way I can call the counting part (in a sub), using href, and my problems will be solved. I think


11-04-2003, 02:07 PM
the link is a normal link with a target="_blank" attribute.

Why don't you just put the statistics code on every page instead of trying to make it work with just one page. You would have to reload the main page everytime you would call the stat page.


Roy Sinclair
11-04-2003, 10:23 PM
Why not just use the IIS Log files to count the hits on pages? Why are you writing all this code to get information which is better tracked another way? Or did anyone ever tell you that any good web server logs all the hits (and a lot of other good information) in files that can then be read to find simple things like how many times a page gets hit? I'm not trying to pick on you, I just want to make sure that what you're trying to do wouldn't be simpler if you approached it from a different angle.

There's even software you can buy to analyse and report the contents of those log files (search for WebTrends).

11-05-2003, 07:27 AM

1. I do not have to reload the main page everytime I call the stat page.

2. I can put the stat code in each page as a sub for example, but then I wonder how can I call this sub, from a link.(Actually, it's one of my q above)

3. Roy, I wish IIS log files could do that. The targets r not pages of my site, they r other sites (external links).


Roy Sinclair
11-05-2003, 03:58 PM
The targets of the links you want to track aren't on your site but the links are?

Why not make all the links point to a single local link and pass the real url as a parameter. That single page receiving the link could log the usage and then redirect the user to the link that was passed to it. That way you don't have to add tracking code to all your pages.

11-06-2003, 07:41 AM
>>The targets of the links you want to track aren't on your site >>but the links are?


Well, that is what I did in the first place. And my problem is:

All works but when clicking the link, the current displayed page is replaced with the log file (blank page - asp page that updates the usage database), and then the target site is opened (in a new window or not, as I choose), using redirect or another option.

I just do not want the log file to appear, I need something like "echo off", and the user to see only the target link.

11-06-2003, 03:09 PM
I think then that your problem is you're outputting HTML. Send this stuff to a pure asp page that has nothing more than:

Function IsURL(str)
Dim iuRegEx
Set iuRegEx = New RegExp
iuRegEx.Pattern = "(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?"
IsURL = iuRegEx.Test(str)
End Function

link = Request.QueryString("L")
If IsURL(link) Then
'Code to write the link into your database
Response.Redirect("http://badlinksupplied.asp") 'You get what I mean here I'm sure
'Or better yet just call a subroutine that displays an error message
End If

The only way it could be showing anything before you redirect is if you're providing some kind of output in the form of HTML, text, or whatever...