1

Topic: eval js and a tag script

Greetings to all.
Prompt. If at me is js the code written down  lines in a variable. How it is possible to execute it without using eval?
EXAMPLE:
var jsCode = ' window. Atr1=2; ';
eval (jsCode);//THERE IS LIE OF ALTERNATIVE?
alert (window. Atr1);

2

Re: eval js and a tag script

Whether it is possible to execute somehow js the code stored in a variable  lines with the help for example tag SCRIPT?

3

Re: eval js and a tag script

Whether

Ichisen wrote:

It is possible to execute somehow js the code stored in a variable  lines with the help for example tag SCRIPT?

As a variant...

<! DOCTYPE html>
<html>
<head>
<meta http-equiv ='Content-Type ' content ='text/html; charset=windows-1251 '/>
<! -
<script src ='https://code.jquery.com/jquery-latest.js'> </script>
<script src = "https://code.angularjs.org/1.3.9/angular.min.js"> </script>
<script src = "https://code.angularjs.org/1.3.9/angular-route.js"> </script>
-->
<style type ='text/css'>
</style>
<script type ='text/javascript '>
</script>
</head>
<body>
</body>
<script type ='text/javascript '>
var str ='alert ("Ok") ';
var o=document.createElement (' script ');
o.type ='text/javascript ';
o.innerHTML=str;
document.body.appendChild (o);
</script>
</html>