I have several pages with hundreds of ‘notes’ hyperlinks to HTML pages. I want to modify behavior so that, instead of simply opening the notes page in a new tab like it does now, the page opens up with some new, common HTML code added to the notes page. Currently, I’m using JS to add an event handler to the links to modify the action to open a template PHP file and pass in the filename of the clicked link. I’m not married to this method but it does work.
iframe or embed of the notes page works, but those tags do not lend themselves to responsive pages.
I found that PHP include 'notespage123.html' works great except for this problem:
Older notes pages were created via MS Word, newer notes pages were created with LibreOffice Writer. The newer pages look fine. The older pages have a bunch of garbage (black diamonds with ?) in them.
So, any ideas how I can import the HTML of either generation of pages and it look correct?
I haven’t tried using JS to import the page contents, but I suspect I’d have the same issue.
Is there a way to open the notes page as-is and then inject some HTML or JS into it?
The content is responsive. The horizontal scroll bar is not a problem with an iframe. It is setting the vertical size that is the problem - I haven’t figured out how to make the iframe height to be as high as the content at any screen width. I have to set a fixed height, which I really don’t want to do.
If your ‘notes’ contain only text, I think you could use JavaScript fetch or XMLHttpRequest to read your HTML files and extract the text content. The text could then be inserted into your web page by inserting <p> elements for each paragraph…
With JS, is there a way to import the HTML DOM and and then insert only the ‘body’ element? That may result in other issues, but I’d still like to try it.
EDIT: I did import only the body node via xhr.responseXML.getElementsByTagName('body')[0].outerHTML (or more concisely responseXML.body.outerHTML) and it avoided the garbage characters! Although, some of the formatting was lost, as I expected, but it is usable. (Ah! If I also add the style node, then it looks just like the original!) So now I have two solutions to decide from.