Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Can a website prevent an element from being added to the already loaded page?

If the code below is run in DevTools or in the browser's address bar, the h1 element will be inserted at the end of a website's page.

const elm = document.createElement('h1')
const txt = document.createTextNode('New text')
elm.appendChild(txt)
document.body.appendChild(elm)

Can any site prevent this from happening using, for example, MutationObserver?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A simple way would be to overwrite the appendChild on document.body so that calling it does nothing.

// page code:
document.body.appendChild = () => {};

// user code:
const elm = document.createElement('h1')
const txt = document.createTextNode('New text')
elm.appendChild(txt)
document.body.appendChild(elm)

A MutationObserver would work too - observe the document.body for childNode changes, and call .remove() on all of the added nodes (available inside the callback's parameter).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!