Adding a Javascript PopUp Window to HTML

You can add Pop-Up functionality to a web page quickly and easily with a little Javascript. This is useful for help screens or any other informational screens where you don’t need a browser window with full functionality and you don’t want to lose your existing page.To do this, add the following to the <HEAD> portion of your HTML document:

<  SCRIPT LANGUAGE="JavaScript" type="text/javascript>
< !-- Begin
function popexternal( h ) {
   if( h ) {
      var offsite = window.open( h, "offsite", 'width=800, height=600, left=5, top=5, menubar=no, scrollbars=yes, resizable=yes, toolbar=no' );
      offsite.focus();
   }
}
// End -->
< /SCRIPT>

Then set up your href links like this:

<a href="javascript:popexternal( '/help.html' )">HELP!</a>

This will open a new browser window with the geometry specified in the ‘function’ and display the relative URL ‘help.html’.

In Perl, you can add the same Javascript function to your page like this:

my $jscript   =<<END;
function popexternal( h ) {
   if( h ) {
      var offsite = window.open( h, "offsite", 'width=800, height=600, left=5, top=5, menubar=no, scrollbars=yes, resizable=yes, toolbar=no' );
      offsite.focus();
   }
}
END

# Page header, etc
print header, start_html(-title  => "Basic Web Page ",
                         -script => {-language => 'JAVASCRIPT', -code => $jscript},
                        );

As of this writing, this method of generating a pop-up is NOT captured by Windows XP SP2’s pop-up blocker.

Comments are closed.