A
Adriano
Dear all,
Is it possible to insert a new javascript tag through the innerHTML
(and use it of course)?
In the following example, the click on a button, insert in a div a
string (TESTO) containing a table and a javascript tag with a function
alert1.
If one tries to use alert1, a js error "alert1 is not defined" is
reported
Is there a solution to this problem?
Of course everythings is ok if the js tag is in the initial file. But I
don't need that.
Thank you for any answer.
Adriano
Example:
=============================================
FIRST.html
=============================================
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" >
<head>
<script language="javascript">
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;
var isNS6 = strUserAgent.indexOf("netscape6") > -1;
var isNS4 = !isIE && !isNS6 &&
parseFloat(navigator.appVersion) < 5;
var req;
function caricaTesto (url)
{
var TESTO= "" +
"<script language='javascript'> " +
"<!-- " +
" function alert1 (url) " +
" { " +
" alert(url); " +
" } " +
"--> " +
" <\/script> " +
" " +
"<table border='1'> " +
"<tr><td>PROVONA</td></tr> " +
"<tr><td> " +
"<input type ='button' value='QUESTO BOTTONE'
onclick=\"alert1('http://172.16.0.52/testo.txt')\"> " +
"</td></tr> " +
"</table> " ;
document.getElementById("tabella").innerHTML = TESTO;
}
</script>
</head>
<body>
<h1>Request Testuale</h1>
<div id="aaa">
PROVA
<input type ="button" value="QUESTO BOTTONE"
onclick="caricaTesto('http://172.16.0.52/prova.html')">
</div>
<br><br><br><br>
<div id="tabella">
INZIO
</div>
</body>
</html>
Is it possible to insert a new javascript tag through the innerHTML
(and use it of course)?
In the following example, the click on a button, insert in a div a
string (TESTO) containing a table and a javascript tag with a function
alert1.
If one tries to use alert1, a js error "alert1 is not defined" is
reported
Is there a solution to this problem?
Of course everythings is ok if the js tag is in the initial file. But I
don't need that.
Thank you for any answer.
Adriano
Example:
=============================================
FIRST.html
=============================================
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" >
<head>
<script language="javascript">
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;
var isNS6 = strUserAgent.indexOf("netscape6") > -1;
var isNS4 = !isIE && !isNS6 &&
parseFloat(navigator.appVersion) < 5;
var req;
function caricaTesto (url)
{
var TESTO= "" +
"<script language='javascript'> " +
"<!-- " +
" function alert1 (url) " +
" { " +
" alert(url); " +
" } " +
"--> " +
" <\/script> " +
" " +
"<table border='1'> " +
"<tr><td>PROVONA</td></tr> " +
"<tr><td> " +
"<input type ='button' value='QUESTO BOTTONE'
onclick=\"alert1('http://172.16.0.52/testo.txt')\"> " +
"</td></tr> " +
"</table> " ;
document.getElementById("tabella").innerHTML = TESTO;
}
</script>
</head>
<body>
<h1>Request Testuale</h1>
<div id="aaa">
PROVA
<input type ="button" value="QUESTO BOTTONE"
onclick="caricaTesto('http://172.16.0.52/prova.html')">
</div>
<br><br><br><br>
<div id="tabella">
INZIO
</div>
</body>
</html>