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?
CodePudding user response:
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.
CodePudding user response:
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>