Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
.innerhtml and javascript problem
Old 09-30-2008, 11:19 AM .innerhtml and javascript problem
Junior Talker

Posts: 2
Trades: 0
Hi chaps,

I have this social networking script at the foot of my page:

<script language="JavaScript" type="text/javascript">
var addtoLayout=0;
var addtoMethod=1;
var AddURL = encodeURIComponent("url goes here");
var AddTitle = escape("title goes here");
</script>
<div id ="bobbus">
<script language="JavaScript" src="scripts/addto/addto.js" type="text/javascript"></script>
</div>

However, I don't want it to load immediately but only after a 5 second timer expires. Using a javascript timer and a .innerhtml command I can do all sorts of things except make this work.

Here's the code snippet:

varHTML0 = "Hello World";
varHTML1 = "<script language='JavaScript' src='scripts/addto/addto.js' type='text/javascript'></script>";

document.getElementById('bobbus').innerHTML = varHTML1;

The problem is that I have absolutely no idea why this won't work....

Substituting varHTML1 for varHTML0 results in hello world as expected.

Clearly, when using the timer the div with ID bobbus doesn't contain anything at all.

I've tried escaping the characters in every way I can think of but to no avail. Is it because you just can't do this with bits of script and expect the browser to process the newly inserted text (script) as normal?
nolfese is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-30-2008, 12:30 PM Re: .innerhtml and javascript problem
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Is it because you just can't do this with bits of script and expect the browser to process the newly inserted text (script) as normal?
Yep. ....
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-30-2008, 03:53 PM Re: .innerhtml and javascript problem
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
It is possible, however, to pull JavaScript onto your page and execute it, on demand. It is done with AJAX. Here is a guide: http://ajaxpatterns.org/On-Demand_Javascript
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 10-01-2008, 08:58 AM Re: .innerhtml and javascript problem
Junior Talker

Posts: 2
Trades: 0
Thanks for the link wayfarer07 that was - I hope - exactly the answer I was looking for. I'll let you know how it goes....
nolfese is offline
Reply With Quote
View Public Profile
 
Old 10-01-2008, 10:05 AM Re: .innerhtml and javascript problem
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
If you ever start using jQuery, it is super easy to pull scripts in on demand, and is done like this:
Code:
$.getScript("/path/to/script.js", function() {
//callback function to execute when script has finished loading goes here.
});
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to .innerhtml and javascript problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29082 seconds with 12 queries