Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Newbie Javascript question...
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
nahpets
Veteran
Veteran


Joined: 05 Oct 2003
Posts: 1178
Location: Montreal, Canada

PostPosted: Fri Mar 04, 2005 12:12 pm    Post subject: Newbie Javascript question... Reply with quote

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
View user's profile Send private message
Oxyron
n00b
n00b


Joined: 12 Aug 2004
Posts: 38
Location: Lithuania, Vilnius

PostPosted: Fri Mar 04, 2005 2:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
ctt
Tux's lil' helper
Tux's lil' helper


Joined: 05 Feb 2005
Posts: 136

PostPosted: Fri Mar 04, 2005 2:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
nahpets
Veteran
Veteran


Joined: 05 Oct 2003
Posts: 1178
Location: Montreal, Canada

PostPosted: Fri Mar 04, 2005 5:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
nahpets
Veteran
Veteran


Joined: 05 Oct 2003
Posts: 1178
Location: Montreal, Canada

PostPosted: Fri Mar 04, 2005 5:06 pm    Post subject: Reply with quote

[edit: removed double post]

Last edited by nahpets on Fri Mar 04, 2005 9:15 pm; edited 2 times in total
Back to top
View user's profile Send private message
UncleOwen
Veteran
Veteran


Joined: 27 Feb 2003
Posts: 1493
Location: Germany, Hamburg

PostPosted: Fri Mar 04, 2005 5:17 pm    Post subject: Re: Newbie Javascript question... Reply with quote

nahpets wrote:
No PHP, no SSI etc... but CGI works


PHP can work over CGI.
Back to top
View user's profile Send private message
nahpets
Veteran
Veteran


Joined: 05 Oct 2003
Posts: 1178
Location: Montreal, Canada

PostPosted: Fri Mar 04, 2005 9:14 pm    Post subject: Re: Newbie Javascript question... Reply with quote

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
View user's profile Send private message
solomonHk
Apprentice
Apprentice


Joined: 28 Mar 2004
Posts: 226
Location: int main(void) { };

PostPosted: Fri Mar 04, 2005 9:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum