2

I have created notes in html file locally and intend to use the file only locally in my computer. Let's say i have a code

<p> this is an example text</p>

I want to select the word example in the browser and preferably press a shortcut to change the code as

<p> this is an <span class="highlight">example</span> text</p>

and save this change in the same html file.

Especially, I have no clue on how to approach saving the changes in the same local html file.

Edit: I intend to use this notes only for personal use and will be only locally stored in my computer as a .html file.

Edit2: Can this be achieved using php?

2 Answers2

2

but I have no clue on how to approach saving the changes in the same local html file.

You can't change the source code of your HTML/JS/CSS file from browser. It posses a serious security risk to your application and hence will be prohibited by the browser.

If you want to remember that you have made this change, then save a value in either localstorage or cookie so that your program read this value at startup and make the change in your markup without a user event.

gurvinder372
  • 66,980
  • 10
  • 72
  • 94
  • Since, I am intending to use the notes only for my personal use and store it locally in my computer, I am not worried about the security concerns or vulnerabilities if there is a way to achieve saving the changes in the same local html file. – Nemo Chappie Mar 10 '16 at 07:26
  • 1
    OK, but the browser doesn't know that. – xlecoustillier Mar 12 '16 at 14:48
0

You can't write to the file system using HTML only - you can however use JS to generate an AJAX request to a server side script (ie PHP/Node/etc.) which in turn writes to a file.

You could retrieve most of the contents by accessing document.body.parentNode.innerHTML changes you've made to DOM since loading the page should be reflected here. It's worth noting that this attribute will not include the HTML tag, or the DTD - it will only include the head and body tags so you'll need to be sure to add them in your server side script.

Brian
  • 2,822
  • 1
  • 16
  • 19