Reputation: 1
I have a site with static pages html and a javascript file that displays an informational message on the page. Is there a way to start the .js file in all pages without having to write the file .js on every page of the site? for example with htaccess or other system
I'm not talking about redirecting to another page but on the page. I know little of .htaccess so if you enter the code examples .htaccess, try it, I'd be grateful. I hope that at least in this forum there is someone who knows how to help me.
Thanks for the answers.
REPLY: I must only add <script type="text/javascript" src="info.js"> </script>
before of </body>
but, there are many hundreds of pages. Notepad ++ is simple, but I will take many days to edit them all manually. I was wondering if there was a faster solution.
Upvotes: 0
Views: 470
Reputation: 10963
Perhaps you can instruct Apache to do some on the fly data manipulation which adds the include for that file to your code.
But if you are able to do this, you should not do this every time the page gets displayed. As you say the content is static, so why not download it, have a program do the adjustments and upload the content again ?
Depending on how the JS needs to be added the page this can be some easy trick with any open source text editor like notepad++.
Notepad++ allows you to automatically replace in files, call Ctrl+Shift+F
or choose this from the menu:
Either way will open this dialog:
Then simply have </body>
replaced with <script ...>...</script></body>
.
If this is the first time you use this function, you should only work with a copy of your important data !
Upvotes: 0
Reputation: 22911
It is possible with a server side scripting language. For example, in PHP, you can add do something like the following, but you'd have to put <?php include("header.php"); ?>
in your files. But if you change things down the line, you would only have to edit a file once.
<html>
<head>
<title>Blah...</title>
<?php include("header.php"); ?>
</head>
....
With .htaccess
, you may be able to rewrite every file to a script like PHP, which will then find the file, read it, and inject the header where it needs to go. (On a busy site, this would be a very inefficient solution).
My recommendation: Just use an editor like Notepad++
and do a quick find/replace on the entire directory to replace </body>
with <script ...></body>
. Would be a quick, and simple solution.
Upvotes: 1