GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes Inner HTML not running JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Inner HTML not running JavaScript" Watch "Inner HTML not running JavaScript" New topic
Author

Inner HTML not running JavaScript

Luke Powl
Greenhorn

Joined: Jul 01, 2011
Posts: 5
So i have this script running (which works perfect) The REL attribute is linked to a Jquery plugin called Shadow box that is the only thing I need to get working. Currently it seems that Javascript is not even running within the innerhtml.




Then it displays the page on the side of my other page perfectly. Now the problem I am having is i need to run Javascript from that innerhtml ,

My Innerhtml is

Any Ideas why my page is not loading JavaScript?

I appreciate any help in advance!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Just shoving script into innerHTML isn't going to make it run.

You say you are using jQuery, so why aren't you using it to do your Ajax? jQuery will cause the script to execute when loaded with the .load() method.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Luke Powl
Greenhorn

Joined: Jul 01, 2011
Posts: 5
The jquery loads when you click on the link. Not when the page is loaded . Not sure if that helps you undestand what im doing ?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
putting JavaScript on the page with innerHTML is not going to run. The browser does not evaluate it.

Libraries like jQuery pull out the scripts and eval() it.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Not sure if that helps you undestand what im doing ?
Then let me summate: you are loading some HTML and script, generated by PHP, from the server via Ajax. The script in this loaded block is not executing when you insert the block into the DOM using innerHTML.

Is that correct?

If so, my reply stands.

[As does Eric's which says the exact same thing I said.]
Luke Powl
Greenhorn

Joined: Jul 01, 2011
Posts: 5
Thank you! I understand now, And i am unsure how to change from ajax to jquery simply. It sounds almost a hassle but I guess i have the itme ill switch over.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Loading an element with jQuery:

Doesn't seem like rocket science to me!
Luke Powl
Greenhorn

Joined: Jul 01, 2011
Posts: 5
FYI,
This worked inside the innerHTML


<img style="cursor:pointer" src="<?php echo $this->url('images/layout3/icons/icon-bandwidth.gif')?>" onclick="Shadowbox.open({ content:'<?php echo $this->url("networktools/".$c->ip."/bandwidthgraph");?>', width:'750',height:'580', player:'iframe'}); return false;" >
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61298
    
  66

Yeah, there's no script block in that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner HTML not running JavaScript