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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open in a new window 1

Status
Not open for further replies.

bluedragon2

IS-IT--Management
Jan 24, 2003
2,642
US
I have a perl script that creates a web page. Is it possible to have the script open in a new browser window and since the page refreshes every 20 seconds, will it keep opening new windows? An example of my header is:

Code:
print "Content-type: text/html\n\n";
print"<HTML><HEAD><meta http-equiv = 'refresh' content = '20'>\n";
print "<HEAD><TITLE>LTM Application</TITLE></HEAD>\n";
print "<BODY BGCOLOR=FFFFFF TEXT=000000 LINK=#0000dd VLINK=#0000dd>\n";

Thanks,

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Not really a Perl question, but... refreshes will continue to happen in the same window, so that should be fine.

The opening of a new window is governed by the link that leads to your perl script; for example by adding a target=_new to the <a> tag.

Annihilannic.
 
* target="_blank"

_new creates a new window named "_new"... so further clicks with target="_new" will make that old window go to the new page instead of making another new window. So ya want "_blank" which always makes new windows.

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
That is the problem, I can not change the link that opens the window. I was wondering if it was possible withing the code. I have researched other places and it does not appear so.

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Well if you want the page to keep opening itself every 20 seconds, why not do...

Code:
<script type="text/javascript">
// 20,000 ms = 20 sec
setTimeout("window.open(self.location.href)", 20000);
</script>

For Perl, just make it print this on the page.

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
I don't want the page opening every 20 seconds just refresh every 20 seconds.

What I was looking for is if a link that I can not control is clicked, it opens in a new window.

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
I have something similar to this on my site... any link that begins with http: and the domain isn't one of my site's domains, JS changes the link's target to _blank.

It was mainly a way to circumvent the W3C's HTML validator, since HTML 4.01 says that "target" isn't a valid attribute for the <a> tag (HTML 5 undoes this and makes target a valid attribute again)...

My code does a couple other things with links in addition to this, but here's just the parts that do this:

Code:
var localAddr = new Array();
localAddr[0] = "kirsle.com";
localAddr[1] = "[URL unfurl="true"]www.kirsle.com";[/URL]
localAddr[2] = "kirsle.net";
localAddr[3] = "[URL unfurl="true"]www.kirsle.net";[/URL]
localAddr[4] = "kirsle.org";
localAddr[5] = "[URL unfurl="true"]www.kirsle.org";[/URL]

if (document.getElementsByTagName) {
   var links = document.getElementsByTagName("a");

   for (var i = 0; i < links.length; i++) {
      var loc = links[i].href;

      // Continue with link formatting by protocol.
      var parts = loc.split ("/"); // http, null, domain name, request
      var prot = parts[0].split(":");
      var protocol = prot[0];
      protocol.toLowerCase;
      if (protocol == "http" || protocol == "https") {
         // This is an absolute URL.
         var isLocal = 0;

         for (var j = 0; j < localAddr.length; j++) {
            if (parts[2] == localAddr[j]) {
               isLocal = 1;
            }
         }

         if (isLocal == 1) {
            // Local links don't need to be modified.
         }
         else {
            // Remote links need to open in a new window.
            links[i].target = "_blank";
         }
      }
   }
}

Kirsle.net | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Thanks kirsle, I will play around with it.

[Blue]Blue[/Blue] [Dragon]

If I wasn't Blue, I would just be a Dragon...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top