If I run the following line in Firebug on any page:
document.documentElement.innerHTML="<script>alert(1)</script>";
why isn’t the alert command executed?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It looks like that your
<script>tag is being added as you expect, but the code within it is not being executed. The same failure happens if you try usingdocument.head(or any other DOM element, it seems). For whatever reason (possibly standards compliance, possible security), inline code inside of<script>blocks that are added via.innerHTMLsimply doesn’t run.However, I do have working code that produces similar functionality:
Here, you add the
<script>block withdocumentElement.appendChildand usetextContentorinnerTextto set the content of the<script>.