Jump to content

HTML editting on-site


mortalc

Recommended Posts

I'm not sure what language/script to use, but the basis is adding text to an HTML webpage.Example:

BobHelloBillHelloBobHow are you?
//Textfield here. Say Bill was logged in, and wanted to reply "I'm fine". He would right it in the textfield, and it would be permanently added to the webpage. So the webpage would always be:
BobHelloBillHelloBobHow are you?BillI'm fine.
Until Someone replies again.How would I do this?
Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

If you wanted it permanent though, you'd want to send the data to the server (via AJAX if you don't want a form submission), which would then store that data in a database which is read by the page when it loads.E.g. http://aspektas.com/blog/an-ajax-shoutbox/.

Link to comment
Share on other sites

Ok...just to make sure, this would work a bit like Facebook messaging, if all goes to plan.Off topic question: How can I command the webpage to close? Example:

var password = prompt ("Password:");if !(password == "Password1") {//Close webpage}

Link to comment
Share on other sites

Ok...just to make sure, this would work a bit like Facebook messaging, if all goes to plan.Off topic question: How can I command the webpage to close? Example:
var password = prompt ("Password:");if !(password == "Password1") {//Close webpage}

you shouldn't. you should just handle the error with a message and let the user close their browser window themselves.
Link to comment
Share on other sites

Ok.That one isn't necessary anyway.Back to the origional problem: Is there any simpler way to do it? If not, then fine. I'll get cracking.

Link to comment
Share on other sites

Even if it were a good idea (thescientist is right; it's not) closing a webpage can be difficult. window.close() will work, but only if the window was opened by one of your own windows. I mean something like, a user opens your document in Window 1. That document opens Window 2. The doc in Window 1 can close Window 2.Otherwise, it cannot be done. That means if your user gets to your page through a link, bookmark, or direct URL entry, you cannot close the window.The reason is simple: it's not your window. Hundreds of documents can have passed through that window, from hundreds of sites, and the user is entitled to keep them in his history, accessible through his back-button or whatever.

Link to comment
Share on other sites

Back to the origional problem: Is there any simpler way to do it? If not, then fine. I'll get cracking.
Well, you can forgo AJAX and other forms of asynchronous action and just have a form that submits to the server, but you lose some of the experience that way.You can also use a plain-text file instead of a database.
Link to comment
Share on other sites

Well, you can forgo AJAX and other forms of asynchronous action and just have a form that submits to the server, but you lose some of the experience that way.You can also use a plain-text file instead of a database.
How do each of those compare for simplicity and experience?Just so I can decide.
Link to comment
Share on other sites

Well, not using AJAX will be simpler. Using a flat file will also probably be simpler.

Link to comment
Share on other sites

Err, well, do you know a server-side language yet? Basically, you just have a page, which reads from the file and displays the replies, along with presenting a form that links to another script that writes to that file.

Link to comment
Share on other sites

Yes, PHP is a server-side language, because it is executed on the server. Anyway, you will need to read about form processing and file I/O.

Link to comment
Share on other sites

I will.I've just had an idea.I've never done it before, so I don't know if it will work.What about HTML DOM?
That's what I originally suggested, however, as Synook said if you want this permanent you'll need one of the methods being discussed here. Just modifying the DOM will be temporary. In other words if the page is refreshed the entire chat conversation will be lost.
Link to comment
Share on other sites

Err, what do you think the HTML DOM is?Basically, you could use DOMDocument() in PHP to load a template as its DOM, and then add the replies into it, then output the modified markup... but you'll still be using PHP and files, and it'll be more complicated. It is not possible to accomplish what you want using JavaScript alone, as it cannot modify server-side resources without the help of a mechanism on the other side (e.g. PHP).

Link to comment
Share on other sites

Err, what do you think the HTML DOM is?
no idea. I just read that it was a way to edit HTML elements.OK. I'll get on with learning PHP.
Link to comment
Share on other sites

The DOM is basically a way of representing markup documents as a set of objects, that can be manipulated. This is useful if, say, you wanted to add another entry to an XML file - you could load the file as its DOM, modify it, and then write the resulting markup back to the file. You still need some way to actually save the contents though.

Link to comment
Share on other sites

Ok...just to make sure, this would work a bit like Facebook messaging, if all goes to plan.Off topic question: How can I command the webpage to close? Example:
var password = prompt ("Password:");if !(password == "Password1") {//Close webpage}

Not really related, but just to have it here, it's never a good idea to have a password stored in a JavaScript file. If you still want it in the JavaScript file, encrypt it, preferably using SHA-256. Also, is that IF valid? Shouldn't it be
if(password != "Password1")

Link to comment
Share on other sites

When you modify a document's contents by changing an innerHTML property, that does change the DOM. There are also so-called DOM methods (such as document_node.appendChild) that change the DOM. Anything that changes the document causes a change to the DOM. Only the methods are different, not their effect.

Link to comment
Share on other sites

I'll try to use the Ajax.But I'm having trouble finding the exact places of the tutorial where I can learn to do this. Any help?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...