View Full Version : Dynamic content / page with JavaScript
johnie
08-10-2002, 02:19 AM
Hi. Is there a way to use Javascript to serve "dynamic" content? For example have some HTML templates and call the content accordingly to the request.
I'm building a static offline site in many languages for use with kiosks and i'm trying to minimize the effort and further development. Do u know of any scripts or a URL that can help me?
Thanks
John
premshree
08-10-2002, 06:47 AM
If you want to display content according to requests, you will have to use a server-side language.
beetle
08-10-2002, 07:34 AM
Well, you can sort of fake it, but you can only have read capabilities (no writing) from the javascript. Take this simple example<script>
var template1 = "<span style=\"color:red\">{DATA}</span>";
var template2 = "<div style=\"color:green\">{DATA}</div>";
var pageContent = "This is a page!";
document.write(template1.replace(/\{DATA\}/,pageContent));
document.write(template2.replace(/\{DATA\}/,pageContent));
</script>A GET variable could be used to 'trigger' the display of any template, or any dynamic content, and the 'templates' could be in an exteral JS file. However, it is strongly recommended that for any serious dynamic content, take premshree's advice, and skip the use of javascript in favor of using something server-side.
johnie
08-10-2002, 09:42 AM
Thanks guys. I know that my solution would be server-side language but i can't use it. That's why i'm turning to Javascript to have as much functionality without having to create 1000's of pages and if i have to change something edit all these pages.
Can Javascript include HTML or text files in its output? Or can it write out the contents of another file?
Thanks
premshree
08-10-2002, 06:07 PM
You cannot read or write contents to any file using JavaScript.
There is one way to read contents through JavaScript, though! and the way is XML! But the problem with this is that not all browsers will support this.
One example :
http://www.dynamicdrive.com/dynamicindex2/xmlticker.htm
Related URL:
http://www.xs4all.nl/~ppk/js/importxml.html
:thumbsup:
MUBNET
08-11-2002, 08:51 AM
Sorry premsheree, but you do mistake in this section.It's avaible to write some inputs to any file.Because you can use ActiveX Control.Example;
<script language="javascript">
var fso = new ActiveXObject("Scripting.FileSystemObject")
var file = fso.OpenTextFile("filepath&name", 1 , true);
file.Write("Hello World !");
file.Close();
</script>
Note: 1 is for Reading
2 is for Writing
8 is for Appending
If you want to more information search it in the javascript.com.
Good luck :thumbsup:
johnie
08-11-2002, 02:27 PM
Thanks a lot. I've found a way to build my templates through search strings. Now i have to find a way for retrieving my content and showing it in the templates.
The normal solution is to call the page in a frame but then if i have to change the layout i'd have to do it in thousands of pages.
Mobnet's solution looks good and i'll give a try.
After all my project wiil run only on windows with IE so it's getting easier for my to skip all the things that would be a problem for other platforms.
If you have other suggestions please post.
Thanks again
John
premshree
08-11-2002, 03:19 PM
Since, you want to support only IE, then MUBNET's idea is great.
If, your content is not very large, then using XML as database is also not a bad idea!
beetle
08-12-2002, 06:04 AM
although I do agree that XML is a better way to go, remember premshree, that if you store javascript variables in an external .js file and use them with your scripts, you ARE reading from a text file. ;)
mordred
08-12-2002, 07:48 AM
It may be fairly obvious, but better mention this than not: Using the FileSystemObject writes to a file on the client, not the server. So I believe to be efficient you have to know where this file lies in the cache to write to it.
Also, it requires IE on Windows platform, and with excruciating low security settings. Might chase people away from your website since they could see the ActiveX-prompt infront of them, which might be perceived as something malicious.
Just my 0.02 Euro.
johnie
08-12-2002, 12:40 PM
What beetle says is already done.
The "website" is not an actual website. It will be located on a single "offline" computer - kiosk where i can change the internet settings for the visitors. There will be only one visitor per time.
The problem is that even i tried to lower the internet settings so that i can execute ActiveX i still get the prompt.
And i can't use relevant paths in the code.
Any suggestions on this?
MUBNET
02-21-2003, 07:02 AM
I can't reach enough to this subject.But I've an idea;
If you use this code as HTML Application(so, .HTA extensioned file)
the prompt will not appear.But it is harder to visit instead of HTML files for the visitors.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.