How can a user open a new window and display XML content in a clear format when clicking a link on an existing HTML page?
To open a new window and display XML content in a clear format when clicking a link on an existing HTML page, you can use JavaScript to open a new window and load the XML content using an XMLHttpRequest. You can then format the XML content using HTML and display it in the new window.
<!DOCTYPE html>
<html>
<head>
<title>Display XML Content</title>
<script>
function displayXMLContent() {
var xmlRequest = new XMLHttpRequest();
xmlRequest.open("GET", "example.xml", false);
xmlRequest.send(null);
var xmlContent = xmlRequest.responseText;
var newWindow = window.open("", "_blank");
newWindow.document.write("<pre>" + xmlContent + "</pre>");
}
</script>
</head>
<body>
<a href="javascript:void(0);" onclick="displayXMLContent();">Click here to display XML content</a>
</body>
</html>
Keywords
Related Questions
- What are the best practices for setting session parameters in PHP scripts to ensure proper functionality?
- How can global variables like $_POST['oper'] be utilized effectively in PHP for image manipulation?
- What are some recommended resources or tutorials for beginners looking to implement a video playlist feature using PHP?