View previous topic :: View next topic |
Author |
Message |
nahpets Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/1571350101426b4fc14d90a.jpg)
Joined: 05 Oct 2003 Posts: 1178 Location: Montreal, Canada
|
Posted: Fri Mar 04, 2005 12:12 pm Post subject: Newbie Javascript question... |
|
|
I'm putting a personal webpage at school, and the webserver configuration is pretty crappy. No PHP, no SSI etc... but CGI works (I can call bash scripts or whatever). So I'm trying to figure out how to do the following:
I want to have a template page that has a navigation column on the left, a header, a footer and a content area in the center. Instead of copying the HTML over and over for every page, I want to use CGI or Javascript to change the text in the content area.
What I REALLY want is some way to include a text from another file with either the "include" or "exec" directives", "<!--exec cgi="cgi-script"-->, but this won't work on my school server. So since my server sucks, I figured I use Javascript and the "document.write" command, but I can't figure out how to read text from a file into some variable and then pass it to "write". Maybe there's another way to execute a CGI script on load?
I've never used Javascript before, and I thought that it would be easy to google for answers, but I didn't find anything useful. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
Oxyron n00b
![n00b n00b](/images/ranks/rank_rect_0.gif)
![](images/avatars/155478973941c44cd96939d.gif)
Joined: 12 Aug 2004 Posts: 38 Location: Lithuania, Vilnius
|
Posted: Fri Mar 04, 2005 2:04 pm Post subject: |
|
|
Javascript is a client side language, so you can't access files from the server and include them with it. CGI's are executables, which generate and output the whole page content. You might write some simple shell script like:
Code: | #!/bin/sh
cat header.html
cat content.html
cat footer.html |
And then add some interactivity (like cat'ing a different file if you pass some option to the script). But be careful with security when writing CGI's, because when not secured properly they can be cracked easily. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
ctt Tux's lil' helper
![Tux's lil' helper Tux's lil' helper](/images/ranks/rank_rect_1.gif)
Joined: 05 Feb 2005 Posts: 136
|
Posted: Fri Mar 04, 2005 2:20 pm Post subject: |
|
|
Oxyron wrote: | Javascript is a client side language, so you can't access files from the server and include them with it. CGI's are executables, which generate and output the whole page content. You might write some simple shell script like:
Code: | #!/bin/sh
cat header.html
cat content.html
cat footer.html |
And then add some interactivity (like cat'ing a different file if you pass some option to the script). But be careful with security when writing CGI's, because when not secured properly they can be cracked easily. | You can dynamically load XML documents. If the loaded XML document happens to contain an XHTML tree, you can easily stitch it into the current document...let's see...
Code: |
g_xml_doc = null;
/* you'll have to change this for IE. It involves conditioning on some variable that's unique
to IE/Mozilla. A quick google should help you out */
function load_xml_and_run(xmlfile, func) {
g_xml_doc = document.implementation.createDocument('','',null);
g_xml_doc.addEventListener('load', function() { func(g_xml_doc); }, false);
g_xml_doc.load(xmlfile);
}
/* replace element_to_append_to with the id attribute of an element in your static (X)HTML.
You can do this by injecting a <span /> or <div /> where you want the new content to be
inserted.
*/
function insert_xhtml(xml_doc) {
document.getElementById('element_to_append_to').appendChild(xml_doc);
}
/* replace some_xhtml_fragment.xml with the name of the xml file containing the XHTML
fragment. The root element should be an some inner XHTML element, rather than
<html />.
*/
load_xml_and_run('some_xhtml_fragment.xml', insert_xhtml);
|
This will only work in Mozilla based browsers, but the XML loading portion is the only thing that would have to change if you're clients are IE. I'm not exactly sure on the syntax, but it involves using some predefined objects for XML loading--Google should figure it out. _________________ - chris |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
nahpets Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/1571350101426b4fc14d90a.jpg)
Joined: 05 Oct 2003 Posts: 1178 Location: Montreal, Canada
|
Posted: Fri Mar 04, 2005 5:06 pm Post subject: |
|
|
Oxyron wrote: | Javascript is a client side language, so you can't access files from the server and include them with it. CGI's are executables, which generate and output the whole page content. You might write some simple shell script like:
Code: | #!/bin/sh
cat header.html
cat content.html
cat footer.html |
And then add some interactivity (like cat'ing a different file if you pass some option to the script). But be careful with security when writing CGI's, because when not secured properly they can be cracked easily. |
Yeah, I figured that this is probably the only way to get this done. I figured out a way to use JavaScript to execute a function that calls "document.write" to generate the content, but it's pretty ugly... |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
nahpets Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/1571350101426b4fc14d90a.jpg)
Joined: 05 Oct 2003 Posts: 1178 Location: Montreal, Canada
|
Posted: Fri Mar 04, 2005 5:06 pm Post subject: |
|
|
[edit: removed double post]
Last edited by nahpets on Fri Mar 04, 2005 9:15 pm; edited 2 times in total |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
UncleOwen Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
Joined: 27 Feb 2003 Posts: 1493 Location: Germany, Hamburg
|
Posted: Fri Mar 04, 2005 5:17 pm Post subject: Re: Newbie Javascript question... |
|
|
nahpets wrote: | No PHP, no SSI etc... but CGI works |
PHP can work over CGI. |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
nahpets Veteran
![Veteran Veteran](/images/ranks/rank_rect_5_vet.gif)
![](images/avatars/1571350101426b4fc14d90a.jpg)
Joined: 05 Oct 2003 Posts: 1178 Location: Montreal, Canada
|
Posted: Fri Mar 04, 2005 9:14 pm Post subject: Re: Newbie Javascript question... |
|
|
UncleOwen wrote: | nahpets wrote: | No PHP, no SSI etc... but CGI works |
PHP can work over CGI. |
Can you tell me how to do that? I'm pretty new to all this web development stuff...
Oxyron wrote: |
But be careful with security when writing CGI's, because when not secured properly they can be cracked easily.
|
I managed to get it working using a bash script and the "cat" command. Can you explain how to properly secure the script so that I don't get @$@# by some hacker? |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
solomonHk Apprentice
![Apprentice Apprentice](/images/ranks/rank_rect_2.gif)
![](images/avatars/97049123341fc78c087e7a.gif)
Joined: 28 Mar 2004 Posts: 226 Location: int main(void) { };
|
Posted: Fri Mar 04, 2005 9:21 pm Post subject: |
|
|
You can also use the echo command in Shell scripts. So
Code: |
#!/bin/sh
echo '<HTML>'
echo '<TITLE> THIS EXAMPLE SUCKS</TITLE>'
|
Lets say that is the header, and you have a nav file
Code: |
#!/bin/sh
echo '<LIST>'
echo 'OPT 2 <br>'
echo 'OPT 3 <br>'
echo 'OPT 4 <br>'
echo '</list>'
|
Then its just a matter of catting it all in another shell script.
There are all flavors of ways to do what you want through CGI.
GOOD LUCK! |
|
Back to top |
|
![](templates/gentoo/images/spacer.gif) |
|