gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
function replaceHTML(oldHTML, newHTML)
- User
function replaceHTML(oldHTML, newHTML)
- Assistant
Here's a simple JavaScript function that replaces the entire HTML content of the webpage with new HTML content:
function replaceHTML(oldHTML, newHTML) { // Check if the current HTML matches oldHTML if (document.documentElement.outerHTML === oldHTML) { // If it matches, replace the entire document's HTML with newHTML document.documentElement.innerHTML = newHTML; } else { console.warn('Current HTML does not match oldHTML.'); } }Explanation:
document.documentElement.outerHTMLgets the entire current HTML including the<html>tag.- We compare it with
oldHTML. - If it matches, we replace the inner HTML of the
<html>element withnewHTML.
Alternative (replace the body only):
If you want to replace only the contents inside
<body>:function replaceHTML(oldHTML, newHTML) { if (document.body.innerHTML === oldHTML) { document.body.innerHTML = newHTML; } else { console.warn('Current body HTML does not match oldHTML.'); } }
Let me know if you want a more specific use case or details!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.