-2

I have this HTML file:

<html><head>
<!--
<meta http-equiv="refresh" content="5">
-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

</td><td align="center"><strong><font face="Verdana" color="#006EC7" size="2">
NETWORK MANAGEMENT CARD FOR UPS</font></strong></td><td valign="center"><div><strong><font face="Verdana" color="#006EC7" size="1">
ON-LINE<br>
Location:
TK01<br>
<span>
11/08/2022 09:59:41</span>
</font></strong></div></td></tr></tbody></table>    
<div style="position: static !important;"></div></body></html>

How can I add the text after the Location from this HTML to another HTML file?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Nikos
  • 1
  • 1
  • The HTML is malformed and invalid. Please [edit] your question to show what research you have done and any attempts you've made based on that research. – Heretic Monkey Aug 23 '22 at 14:45
  • Does this answer your question? [Transfer data from one HTML file to another](https://stackoverflow.com/questions/17502071/transfer-data-from-one-html-file-to-another) – Heretic Monkey Aug 23 '22 at 14:58

2 Answers2

0

This is your server's job. Since you did not specify what server-side technologies you are using, I will provide you general ideas.

So, if you want the part of

Location:
TK01<br>
<span>
11/08/2022 09:59:41</span>

to appear at multiple pages, then you will need to make sure it is a template (it could be a twig, a blade file, even a PHP file or function or whatever) that your server-side code loads when generating your page and puts it into the correct location.

Example

templates.php

function Location() {
    return "
        Location:
        TK01<br>
        <span>
        11/08/2022 09:59:41</span>
    "
}

Then you can include or require templates.php and call the function at the correct location, like

mypage.php

<?php
    require "somepath/templates.php";
?>
<html><head>
<!--
<meta http-equiv="refresh" content="5">
-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

</td><td align="center"><strong><font face="Verdana" color="#006EC7" size="2">
NETWORK MANAGEMENT CARD FOR UPS</font></strong></td><td valign="center"><div><strong><font face="Verdana" color="#006EC7" size="1">
ON-LINE<br><?php echo Location(); ?>
</font></strong></div></td></tr></tbody></table>    
<div style="position: static !important;"></div></body></html>

You can of course use different technologies and you can also parameterize your templates as you wish, the above is only a basic example of how you could solve this issue, but I would in no means say that this is how you should do it. It is up to you to choose the approach you prefer.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • This makes a huge assumption that the OP is the creator/owner of the HTML document. – Heretic Monkey Aug 23 '22 at 14:46
  • @HereticMonkey that's true. The reason for this assumption is the quote from the question: "I have this HTML file". My understanding is that "I have this HTML file" means that the asker has that file, that is, the user owns that file. – Lajos Arpad Aug 23 '22 at 14:50
  • They may have the file, but not own it, and may have had no hand it creating it. In any case, simply asking before answering is a good way of converting assumptions into certainties. But then you wouldn't get your answer out first on a duplicate question. So bravo for that. – Heretic Monkey Aug 23 '22 at 14:58
  • @HereticMonkey again: I assume that the asker has the file, because of the quote above. I'm 99.99% sure that the user has the file and has access to it. And I have reasons to assume it. Yet, you criticize me for making this very likely and reasonable assumption, while you assume that the reason I'm not asking about this is that "then you wouldn't get your answer out first". So, while you criticize me for a very likely and reasonable assumption, you are making a less likely and less reasoned assumption. Bravo! – Lajos Arpad Aug 23 '22 at 15:02
  • I can't understand where the problem is. No i haven't create the file. It 's a file that created from the network card that it have my ups. Because i have 23 same ups, i just want to have all the information in one page. but only the information i want. not all the html. thats why i cant use "frameset". thats all. – Nikos Aug 24 '22 at 07:35
0

Assuming the given file is saved as a temp.html file. Also, note that you can't use this if the files are in a different host. You can use the following JavaScript solution to show the location.

<html>
    <body>
        <div id="data"></div>
        <script>
            const xml = new XMLHttpRequest()
            xml.onload = function() {
                if (this.readyState) {
                    const parser = new DOMParser()
                    const doc = parser.parseFromString(this.responseText, "text/html");
                    document.querySelector('#data').innerHTML = doc.querySelector('font[color="#006EC7"][size="1"]').innerHTML.match(/Location:\s*(.+)/)[1]
                }
            }
            xml.open("GET", "./temp.html");
            xml.send();
        </script>
    </body>
</html>
Debashish
  • 511
  • 4
  • 13