Answer the question
In order to leave comments, you need to log in
Script inserted with append not executing?
I entered in the input field , but everything is displayed as text and nothing is executed, how to solve?<script>alert(5)</script>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hacked</title>
</head>
<body>
<input id="in" type="text">
<button id="submit">Отправить</button>
<script>
let input = document.querySelector('#in');
let button = document.querySelector('#submit');
button.addEventListener('click', () => {
let p = document.createElement('p');
p.append(input.value);
document.body.append(p);
});
</script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Why should it be fulfilled?
append - https://learn.javascript.ru/modifying-document
It adds nodes or strings to the end of a node.
To execute code from a string you can use eval()
Take text from a field and shove it into eval()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question