Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Variable interpolation inside an externa js file?
In my perl script I have put my javascript code in a separate file with the
extension of js. I reference it with a javascript tag in the HTML. I have
some code in there that is not in a procedure: it just executes prior to the
body of the page loading as inline statements.

Now I discover I need some of those URLs in my external javascript file to
change depending on some perl parameters.

This is not a procedure so I cannot just change some javascript procedure
parameters. Perl does not process this file so it won't do the variable
interpolation I want either.

Below is the code that is causing the problem.

I think the only way to resolve this is to cut the code below and move it to
the perl code where I can use interpolation (which I would prefer not to do
because it will really clutter up the main program -- oh well).

Can anyone suggest a better approach?

Thanks,
Siegfried


if (document.images) {
one_on        = new Image ();
one_on.src    = "http://www.decisionchannel.com/breturn2.gif";
one_off       = new Image();
one_off.src   = "http://www.decisionchannel.com/return2.gif";
two_on        = new Image ();
two_on.src    = "http://www.decisionchannel.com/f_bwhatbut2.gif";
two_off       = new Image();
two_off.src   = "http://www.decisionchannel.com/f_whatbut2.gif";
... // more of the same
}


Report this thread to moderator Post Follow-up to this message
Old Post
Siegfried Heintze
11-23-04 01:55 AM


Re: Variable interpolation inside an externa js file?
On Mon, Nov 22, 2004 at 01:21:35PM -0700, Siegfried Heintze wrote:
> In my perl script I have put my javascript code in a separate file with th
e
> extension of js. I reference it with a javascript tag in the HTML. I have
> some code in there that is not in a procedure: it just executes prior to t
he
> body of the page loading as inline statements.
>
> Now I discover I need some of those URLs in my external javascript file to
> change depending on some perl parameters.
>
> This is not a procedure so I cannot just change some javascript procedure
> parameters. Perl does not process this file so it won't do the variable
> interpolation I want either.
>
> Below is the code that is causing the problem.
>
> I think the only way to resolve this is to cut the code below and move it 
to
> the perl code where I can use interpolation (which I would prefer not to d
o
> because it will really clutter up the main program -- oh well).
>
> Can anyone suggest a better approach?

I'd suggest loading the js file using HTML::Template. Substitute the code yo
u
want with a <TMPL_VAR />, and write some logic so that if the query string
contains foo.js (a slight oversimplification) that it loads that template,
prints it, then exits. Does that make sense to you? Anyone else?

--
=====================
Shaun Fryer
=====================
http://sourcery.ca/
ph: 416-544-9461
=====================


Report this thread to moderator Post Follow-up to this message
Old Post
Shaun Fryer
11-23-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL CGI Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:18 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.