|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How can I write to a file on the server using JavaScript? If not possible can I run a Server-side script from client-side Javascript, PHP for example? Example: On a onclick event I want to send a function some text of what the user clicked, and save the text into a file or into a database, on My web server.
Thank you, JRM |
|
#2
|
|||
|
|||
|
You could do this by putting an <img> tag somewhere on the page, and changing it's source to a server-side script file (PHP, CGI, ASP, etc.) and pass along the text you wish to store. This server-side script file could then write to the file or database and output a blank image. I'd also have the javascript pass some random string in the src also to make sure the browser requests a new image and doesn't think it is cached.
Shawn iTISTIC.com |
|
#3
|
||||
|
||||
|
javascript will not do this.
you can use cgi or asp. do you have a preference? pick one and i will send you the code. [not sure about that img tag idea.]
__________________
columbus ohio architect | columbus ohio web site designer | sussex county new jersey business directory | columbus ohio |
|
#4
|
|||
|
|||
|
CGI would probably work best. I'm not on a M$ box. Thank you Relaxzoolander
The image thing confused me a little too. I want to track a click on a specific link, not all just a couple. JRM Last edited by JRM : January 30th, 2004 at 08:56 AM. Reason: Adding comment |
|
#5
|
|||
|
|||
|
how to write Hello World to a file on server using javascript or CGI?
Did you manage to find the solution to this problem? if so can you post it on site or send it to me .
Thanks in advance MD |
|
#6
|
|||
|
|||
|
Hi JRM, you can actually use JavaScript to write or read from a file. The only problem is that its Client Side Code which can disabled by the clients browser, rendering you code obsolete. Anyway the imbedded object is a Microsoft active x object called FileSystemObject.
I have include the code here to help you out. Give me a shout if you need more answers. Code:
function WriteToFile()
{
try
{
var fso, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
s = fso.CreateTextFile("C:\\test.txt", true);
s.writeline("This is a test");
s.Close();
}
catch(err)
{
var strErr = 'Error:';
strErr += '\nNumber:' + err.number;
strErr += '\nDescription:' + err.description;
document.write(strErr);
}
}
Make sure you set your file permissions wherever your txt file is to full write permissions, and set your security custom level in IE to initialize active x objects marked as safe. Last edited by SEO_Jonty : August 22nd, 2005 at 10:55 AM. |
|
#7
|
|||
|
|||
|
write on server
He cool it works, but
how should i write on the server, what should be a correct serverroot, i'm no javascript user that's wy i'm asking. please let me know if possible. steve |
|
#8
|
|||
|
|||
|
Quote:
Of course, you can always set up fle permissions to allow writing from a remote server, but this would also allow ANYONE to write ANYTHING to your server that they wanted to , and that's an open invitation for hackers to come and hijack your box. The CGI methods that have been suggested here are the best in my opinion. I'd use PHP because that's what I know, and it's easy to have a function set up that'll write information to a file quickly and easily. |
|
#9
|
|||
|
|||
|
Quote:
I agree, eventhough i supplied the code, it is only an example and using client side code to do this isnt practical for a variety of reasons, one of them being that it is client-side and the user might disable javascript on his browser rendering your code useless. What i do suggest you do, is using a filesystemobject in ASP or if you choose a similar object in PHP. |
|
#10
|
|||
|
|||
|
I want to get ASP sample about wrtie file in server
Quote:
I want to get ASP sample about wrtie file in server |
![]() |
| Viewing: SEO Chat Forums > Other > SEO Scripts > JavaScript Write file on server |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|