Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about CGI.pm..redirect()

Status
Not open for further replies.

lcs01

Programmer
Aug 2, 2006
182
US
My company has a web page created mainly by mod_perl, CGI.pm, & javascript. On this page, when you click on certain links, you may be redirected to a new page depending on your status. The perl code behind is currently implemented this way:

Code:
sub redirect {
  # some implementation here
  if($status) {
    print redirect(-location=>"/newpage.html");
  }
  exit;
}

The implementation above works OK except one thing - it opens a NEW window with the content of 'newpage.html'.

My question is how I can modify the code so that it can use the EXISTING window instead of opening a new one? BTW, I tried start_html() and some javascript approach, but neither works.

Many thanks in advance for your kind help!
 
Try like this:

Code:
sub redirect {
  # some implementation here
  if($status) {
    print redirect("[URL unfurl="true"]http://www.site.com//newpage.html");[/URL]
  }
  exit;
}

You have to use a full URL with a redirect. I assume this is the redirect() function of the CGI.pm module. You also can't print an http header before using the redirect() function.
 
Thanks. the way you suggested still opens a new window. That's not an ideal way.
 
There is no reason it should open in a new window. Something else is causing that to happen.

Also, you have a sub routine named "redirect" that is the same name as the CGP.pm function "redirect". If you use the OO methods with CGI.pm you can get away with that, but it looks like you are using the function style of coding in which case your script is probably using your sub routine named redirect and not the CGI.pm modules redirect function.
 
Thank you, Kevin and Kirsle. And I am so sorry that it took me so long to reply - I've been so busy that I almost forgot coming back to this wonderful forum!

BTW, it's indeed something else causing a new window poped-up.

 
Browser option, perhaps?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
You don't have a 'target' specified as '_blank' by any chance, or you may be able to force the target to '_self'

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top