Help with response.redirect

Hi Guys,

I am trying to put together a banner script for my site. I am using classic ASP.

In a hyperlink - the target property sets the reference for where the hyperlink will lead to - for example target='_blank' will open a new window or tab as the case maybe ...

Response.redirect sends the output to the redirected page in the same browser window. So I can execute some code and depending on the result I can redirect execution to any number of scripts which will always output to the same page.

I have a case where I need to execute some code and depending on the outcome of that code, I need to open a new window (or tab as the case maybe) and present that to the user - leaving my page intact. I have a feeling that I need to use javascript to open a new window and I don't really have a good enough working knowledge of that to implement it.

What would be the best way for that to be accomplished ? Remember, I need to execute some code to process the click on the hyperlink and then redirect the user to a new window, with the URL specified in the hyperlink.

I currently am using a hyperlink with the href property pointed to an asp which processes some data and then redirects the user to the page where I want the user to go - thus taking focus away from my site, which I would like to avoid.

MTIA

DWE
LVL 1
dwe0608Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
'redirects' in any language actually send the redirect response back to the browser window that requested the page.  The actual redirect is done by the browser in the window that made the original request.  Which is why you can't 'redirect' to a 'new' window.
0
dwe0608Author Commented:
Hi DaveBaldwin,

Yes I understand what you say ... however, what I want to do is implement the opening of a new window following the execution of some asp code - ie implement the following

execute ASP code which formulates hyperlink

user clicks on the hyperlink

execute more asp code to log click on hyperlink

open window in new browser window

my hyperlink is currently formulated as follows:

get_banner = "<A href='../ad_click.asp?banner_id=" & nBanner & "' target='" & target & "'><img src='" & banner_image & "' title='" & alt_text & "'></A>"

Open in new window


I know that using the window.open functionality will open a popup blocker if the window is not from the same site - I don't want to bypass that technology - I simply want to execute some asp and then open a new window.

I have given some thought to using the href and onclick functionality together to see how this would work, but not knowing too much about it, and thinking someone else has come across this issue previously, I thought I'd post here ...

MTIA

Regards

DWE
0
dwe0608Author Commented:
I have experimented with the code and found that the following code seems to work - its an extract ...

   ' asp code above actually defines the url but for this example
   url = "http://www.google.com.au"
    '' Need to use another function  rather than redirect
    'response.redirect URL
%>
    <script type="text/javascript">
        var varwin=window.open(url, 'noName', '', true);
    </script>

<%

Open in new window


url is defined in the asp code above where the code snippet begins - but it doesn't seem to be read in the javascript - how can I pass the url to the javascript function ?

MTIA

DWE
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dave BaldwinFixer of ProblemsCommented:
I think this will work.

window.open(<%='http://www.google.com.au'%>, 'noName', '', true);

Open in new window


Or..

window.open(<%=url%>, 'noName', '', true);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dwe0608Author Commented:
yep - I tried that ... doesn't work ... putting an apostrophe either side of the asp code in the window.open function did though ....

    '' Need to use another function  rather than redirect
    'response.redirect URL
    url = "http://google.com.au"

%>
    <script type="text/javascript">
        var varwin=window.open('<%=url%>', 'noName', '', true);
    </script>

Open in new window


Many thanks for the help ... can you think of any other way this could be done ?

DWE
0
hieloCommented:
try:
<%

'do your server-side processing here, setting the variable "url" to the destination url
'...
url = "http://google.com.au"

%>
<html>
<head>
<!-- whatever else your page is already doing here ... -->

<!-- add the following script block-->
<script type="text/javascript">
//if some function is already supposed to be executed on load, save it first
var temp=function(){};
if( window.onload )
{
  temp=window.onload;
}

//define a new function to be executed upon load
window.onload=function(){
  //execute the old function
  temp();

  //click the url
  document.getElementById('theLink').click();
}
    </script>
</head>
<body>
<a id="theLink" href="<%=url%>" target="_blank">Google...</a>
</body>
</html>

Open in new window

0
Dave BaldwinFixer of ProblemsCommented:
No, that's the kind of thing I do in PHP to get the info into a javascript variable or function.
0
dwe0608Author Commented:
Many thanks for the assistance guys

DWE
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.