I need to display HTML from an external javascript file. However, the
?onclick? event does not occur when a <div> tag contains text that is
retrieved from an external javascript file.
To exemplify this problem, please create the following four small files:
==============================================
-------------------------------
1. good.htm:
-------------------------------
<html><head><title>Good</title></head><body>
<script>function DoClick(objDiv){alert('Click is OK.')}</script>
<div onclick=DoClick(this)><script SRC=test2.js></script></div>
</body></html>
-------------------------------
2. bad.htm:
-------------------------------
<html><head><title>Test</title></head><body>
<script src="test1.js"></script>
</body></html>
-------------------------------
3. test1.js:
-------------------------------
document.write("<script>function DoClick(objDiv) {alert('Click is
OK.')}</script> <div onclick=DoClick(this)>From test1.js.</div><br>
<div onclick=DoClick(this)> <script SRC=test2.js> </script></div>")
-------------------------------
4. test2.js:
-------------------------------
document.write("From test2.js.")
-------------------------------
==============================================
The following instructions will demonstrate this problem (use IE 6.0):
1. Display good.htm, and click on ?From test2.js?. An alert window
will indicate that ?Click is OK?.
2. Display bad.htm, and click on ?From test1.js?. An alert window will
indicate that ?Click is OK?.
3. Also from bad.htm, click on ?From test2.js?. The alert window is
not displayed. Therefore, the click event is not occurring.
To solve this problem, the click event must occur in bad.htm, when
?From test2.js? is clicked (after test2.js is displayed from
test1.js). |
Request for Question Clarification by
sublime1-ga
on
29 Dec 2005 12:53 PST
ftppro...
Given the source you've provided for bad.htm, neither
"From test1.js" nor "From test2.js" is displayed to
be clickable, as you've indicated it should be.
sublime1-ga
|
Clarification of Question by
ftppro-ga
on
29 Dec 2005 14:30 PST
Thank you all for your prompt attention to my question. I am willing
to offer an extra $25 to the person who can find a SOLUTION (and not
just an explanation why it can?t be done).
Here are my replies to the responses that you provided:
1. For sublime1: After you remove the line feeds from test1.js, please
confirm that bad.htm works as described.
2. For cascaval: I need a solution which does not require modifying bad.htm.
3. For winista: I need a solution for IE, not Firefox.
4. For everyone: This code will be used to monitor ad clicks. Here are
the requirements:
a. In bad.htm: There can only be one SCRIPT tag, which will eventually
load a javascript file (test1.js) from my server.
In test1.js:
b. In the final version, the DoClick function will contain a reference
to an image file, which will call a script on my server, which will
log each click in my database. For this example, the DoClick function
only needs to display an alert message.
c. Within the DIV tag, the script tag will load a javascript file
from an Ad Network (e.g. Fastclick, Kanoodle, etc.), which will cause
an ad to be displayed on the webpage.
Please provide a modified test1.js which fulfills the requirements described above.
Thanks!
|
Request for Question Clarification by
sublime1-ga
on
29 Dec 2005 18:36 PST
ftppro...
Removing the linefeeds did the trick. Thanks.
|
Clarification of Question by
ftppro-ga
on
29 Dec 2005 19:03 PST
Sublime1:
I hope you can find a solution this issue.
Thanks.
|