dynamic content does not process JAVASCRIPT. need help!

N

namemattersnot

Re,

SCENARIO: User clicks a link and a javascript function creates dynamic
content in <div id="content"></div> using:

document.getElementById("content").innerHTML = something [something is
a variable that holds a chuck of HTML code]

In the page's header I load a javascript that does nice effect to
pictures. In HTML code I have the following element that contains
referect for that said javascript:

<a href="a.jpg" rel="nice_effect">click for nice effect</a>

PROBLEM: Everything is properly displayed, however, javascript is not
activated when the link is pressed.

Now, I can use eval(something) to process a simple request such as
'alert("hello")', but how do I re-eval ALL javascripts that are
included in the page's header OR that are included in the content that
I am creating (i.e. in addition to a bunch of <a> elements, I will
include a <script> element)???

This following page shows a function that goes through the whole HTML
and re-declares all functions that are found in <script></script>
elements: http://www.modernmethod.com/sajax/forum/viewtopic.php?t=205

It appears to be the solution that I need, however, the code doesn't
seem to work (or perhaps I am not using it correctly) and the author
cannot be contacted.

Are there any knowledgeable people in this group who could please help
me? I need the javascript to work with elements that are dynamically
included in the page AFTER it is loaded.

Thank you!!!!!!!
 
V

VK

Re,

SCENARIO: User clicks a link and a javascript function creates dynamic
content in <div id="content"></div> using:

document.getElementById("content").innerHTML = something [something is
a variable that holds a chuck of HTML code]

In the page's header I load a javascript that does nice effect to
pictures. In HTML code I have the following element that contains
referect for that said javascript:

<a href="a.jpg" rel="nice_effect">click for nice effect</a>

<a href="if_script_disabled.html" onclick="nice_effect();return
false;">
Click here for nice effect
</a>
 
N

namemattersnot

VK,

This does not solve my problem nor is how the script activated. The
problem is that dynamically included content is not really included
when you view the source, hence the script (in the header) does not
process it. Nor are processed any JS functions that are included unless
I use eval(function) when or after I include the content.
Re,

SCENARIO: User clicks a link and a javascript function creates dynamic
content in <div id="content"></div> using:

document.getElementById("content").innerHTML = something [something is
a variable that holds a chuck of HTML code]

In the page's header I load a javascript that does nice effect to
pictures. In HTML code I have the following element that contains
referect for that said javascript:

<a href="a.jpg" rel="nice_effect">click for nice effect</a>

<a href="if_script_disabled.html" onclick="nice_effect();return
false;">
Click here for nice effect
</a>
 
G

google

Hello,

It looks like you need to create a function, and then call the function
with the onclick() handler, similar to the code VK posted. Something
like this:

<script type="javascript/text">
function nice_image(some_html) {
document.getElementById("content").innerHTML = some_html;
}
</script>
<a onclick="nice_image([Add HTML here]);">Nice effect</a>

It seems like that should work, no matter where the javascript is
located.

Chris S.
Implied By Design LLC.
http://www.impliedbydesign.com
Free Web Design Tools
http://www.impliedbydesign.com/free-software-scripts.html
 
J

Jonas Raoni

document.getElementById("content").innerHTML = something [something is
a variable that holds a chuck of HTML code]
[...]

Now, I can use eval(something) to process a simple request such as
'alert("hello")', but how do I re-eval ALL javascripts that are
included in the page's header
[...]

This following page shows a function that goes through the whole HTML
and re-declares all functions that are found in <script></script>
elements: http://www.modernmethod.com/sajax/forum/viewtopic.php?t=205

The best thing on this case is to not load the html with javascript
together, which looks strange in my opinion.

I took a look on your link, it's bad written, the regexp is bad and
there are global variables (a lot). It just captures functions and
redeclare them in a bad way (using eval, which isn't needed on this case).

To solve your problem, just collect all the scripts and make a big eval,
just take care to ignore inline script tags (I mean for ex:
alert('<script></script>'), which would break your code deppending of
your approach) and check if the <script> has a src property =]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top