ryansin
ryansin

Reputation: 1817

Can a user permanently amend an HTML file through the browser?

For example- could the user change the actual code of the HTML from the web browser using a JavaScript prompt?

If I had the following code.

<html>
<head>
<script>var person = prompt("Please enter your name");</script>
</head>
<body>
<p>This should be user amendable</p>
<p>This shouldn't</p>
</body>
</html>

I don't mean to store the variable person temporarily, but actually change the HTML code and replace it with the value of the variable?

Upvotes: 0

Views: 238

Answers (2)

tremor
tremor

Reputation: 3186

If your prompt submits the data to a form handler written in PHP or some other server side application, it can access the file system in a way in which you could permanently edit the content, however you should avoid doing this for security purposes without creating a much more robust system in which to check that the information entered into the prompt is not malicious. In short, this is best left to CMS (Content Management System), which are more likely to save the actual "content" of your website as part of a database structure.

Upvotes: 0

Quentin
Quentin

Reputation: 943569

Not as such. Alternatives include:

  • You could take the changes and send them to a server using XMLHttpRequest. The server could respond by storing them and sending the new version to anyone who requested it in future.
  • You could store the changes in local storage / a cookie / etc, and include some JavaScript in the page that looks for that data and updates the page as soon as it loads.
  • A browser plugin could be written that could store modifications to be made to a given URL.

Upvotes: 3

Related Questions