[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Perl variable within Javascript?



Derek--

This works great! And thanks to everyone else for their suggestions 
and support. This will create a lot of happy campers here!

--Eric


> Date:          Wed, 23 Feb 2000 14:20:53 -0500 (EST)
> From:          Derek Lane <derek@duke.edu>
> Subject:       Re: Perl variable within Javascript?
> To:            eric.stedfeld@nyu.edu
> Cc:            perl4lib@VIMS.EDU

> Eric --
> 
> 
> > This is the last piece of a Perl puzzle, for me. I have a Perl 
> > variable $sessionid that holds the value of a user sessionid. I 
> > obtained the value by using my Perl script to connect to our catalog 
> > through its Web interface. Now, I want to use that variable within 
> > some Javascript on a new Web page that the Perl script generates....
> 
> TIMTOWDI. In this case you know what the string should look like, so
> you don't have to be so careful. A simple:
> 
> $html = <<'EOM';
>  <HTML>
>  <HEAD><TITLE>Patron info link</TITLE>
>  <SCRIPT LANGUAGE=Javascript>
>    var iwin;
>    function instruct()
>    {
>        iwin =
>        window.open("http://www.bobcat.nyu.edu/html/PatronCheck.html%3a%
>        3ASESSION_ID", "iwin",
>        "width=550,height=450,scrollbars,resizable,status");
>    }
>  </script>
>  <META HTTP-EQUIV="Refresh"
>  CONTENT="0;URL=http://www.nyu.edu/library/bobst/database.htm";>
>  </HEAD> 
>  <BODY onLoad="instruct()">
>  <BR>
>  </BODY></HTML>
> EOM
> 
> $html =~s/SESSION_ID/$session_id/g;
> print $html;
> # or concat $html in another string using the '.' operator, etc.
> 
> should do it.
> 
> <explanation> 
> TIMTOWDI -There is More Than One Way To Do It. If the content were more dynamic
> I would suggest anything from building it up with concatenation thru the use of 
> Template modules.
> 
> <<'EOM'; 
> is 'here' quoting; appropriate for multi-line strings.
> The single quotes around EOM mean 'don't interpolate'.
> The string is ended by EOM as the entire line (that means it is
> first in the line and there is nothing, not even space, after it).
> 
> We can substitute in the HTML with confidence since most of the
> content of $html is known.
> </explanation> 
> 
> --Derek Lane
> dereklane@pobox.com
> 

=====================
Eric L. Stedfeld
Info Tech Specialist
NYU Libraries
212 995-3545
eric.stedfeld@nyu.edu