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> 2 3945
On Oct 13, 3:59 am, "Adriano" <adip...@gmail.comwrote:
Dear all,
Is it possible to insert a new javascript tag through the innerHTML
(and use it of course)?
Yes, but only in NN6.xx series browsers.
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?
Dynamically create script elements and then set it's .text property.
But for the code you posted, your best alternative is to simply start
over.
--
Randy
Hi adriano,
It doenst work :s sorry.
I dont understand quite well what r u trying to do .. but what does
work for that kind of things is iframes
for example:
with a link
<a href="script.html" target="tabella" lala </a>
u can put a web page called for example script.html with ur script
inside inside the iframe
<iframe name="tabella" ></iframe>
only then ur javascript code is executable because this is a new web
page that initializes the code
and ur script will work fine.
hope that help
Marcos
On Oct 13, 4:59 am, "Adriano" <adip...@gmail.comwrote:
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>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: VictorG |
last post by:
Hello,
I am new to JS and am trying to add some HTML into a JS function. So
that when called the script as well as the HTML will be invoked. Is
there some type of embed mechanism, sort of the reverse of embedding JS
in an html page with the script tag. (which is what I am doing in this
case)
Is this even possible?
|
by: Astra |
last post by:
Hi everybody
Wonder if you could help me out.
I created a simple JavaScript routine to enable a user to click backwards
and forwards between small news articles. This routine works fine in IE and
Safari, but in the latest FireFox I get no title or article, but do see the
prev and next links and the article number.
My HTML and JS...
|
by: e |
last post by:
I've been having an extremely difficult time finding an answer to this in IE
/ js groups, so I thought I'd try here.
I've got an aspx page that delivers loads of report data into custom-named
<span> tags on the client, hidden from the screen by @media classes. From a
dynamically built menu of what was returned, the user selects wich report...
|
by: julian.tklim |
last post by:
Hi,
I need to build an editable Datagrid with add & delete buttons on each
row using javascript.
DataGrid need not be pre-populated with values.
To make the thing complicated, one of the column need to be a date
picker field.
I know things will be easier with ASPX datagrid.
|
by: John |
last post by:
Hi Everyone,
I'm having this extremely annoying problem with Internet Explorer 6,
giving me an error message saying "unknown runtime error" whenever I
try to alter the contents of a <divelement using innerHTML.
Now, I've researched this problem on the web, and found many references
to it, but none of them quite addressed my specific...
| |
by: Christopher Nelson |
last post by:
I have a little menu system which essentially takes HTML like:
<div id='foo'></div>
and retrieves foo.shtml from the server and inserts it inside the
<div>. But sometimes I'd like foo.shtml to look like:
<script language='JavaScript'>
...do something AJAX-y
</script>
|
by: WayneH |
last post by:
Hi -
I'm trying to use javascript to determine if a user's browser has cookies enabled or not.
To test: copy this code into a file with a 'html' extension, and load it into your IE browser directly, through a local web server and through a remote web server.
By turning cookies on/off in your browser, running the file, then clicking the...
|
by: Pratik Patel |
last post by:
Hello,
I used innerHTML to assign HTML content. but in my HTML page content
have also some javascript function and it will run when page load. bu
when HTML code assgin thru innerHTML then this javascript is not
working.
e.g.
html content:
|
by: smartic |
last post by:
i'm having three lists when i select from any one the others be visible by hierarchy but it takes to long to write my code is there is another away to write this code like XML that is my javascript code ex:
function ChangeCategory(ForWhat){
switch(ForWhat.selectedIndex){
case 0:
//if he selected noothing...
|
by: =?Utf-8?B?R1ROMTcwNzc3?= |
last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I
think I'm done for now,...
Is it possible to insert recordset data in a javascript, for instance I have
a javascript code that calculates the total price, depending on number of
units, currently what the code does is set the price like so -
if qty 1 then £99+VAT...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |