The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Simple javascript code doesn't work
Hello.
I'm trying to use this simple code to display ads: Code:
<script type="text/javascript"> init_banners(); function init_banners() { document.getElementById('navabr_720x90').innerHTML = "<script language='javascript' type='text/javascript' src='http://blablabla.com/st?ad_type=ad&ad_size=728x90'><\/script>"; } </script> But the ads doesn't show, if i don't use the function, just paste the script so the ads do show so i dont think the problem is with the ads. Even if i replace the ads link with a simple plain text it DOES work. So how can i fix this? Thanks in advance. |
#2
|
|||
|
|||
Is that element id correct?
|
#3
|
|||
|
|||
Yes, 100% sure.
I copied and paste it, and i also said that if i change the ".innerHTML = "<script..." to just plain text, it does work. |
#4
|
||||
|
||||
You can't shove a <script> tag inside a innerHTML property and expect it to load. You could try using createElement() methods and then appendChild(), but I'm not sure the script would load that way either.
Personally with the script you have I'd just do this: Code:
<div id="navbar_720x90" style="display: none;"><script language='javascript' type='text/javascript' src='http://blablabla.com/st?ad_type=ad&ad_size=728x90'></script></div> <script type="text/javascript"> <!-- function init_banners() { document.getElementById('navbar_720x90').style.display = ''; } init_banners(); --> </script> |
#5
|
|||
|
|||
Still using both "navbar" and "navabr" as id.
|
#6
|
||||
|
||||
Never saw that typo, thanks Marco
|
#7
|
|||
|
|||
I can't use this script because the purpose of the function i built was to load the ads, as the latest thing on the page. because they are located on an external sever (nothing i can do about that), and because it takes them too much time to load they make the page stuck, so until they are finally load, you can't see the rest of the page. after they load completely the rest of the page shows up. and this process takes about 15 seconds more than i want to. Do you have a better way to fix it?
|
#8
|
||||
|
||||
Well after testing, it seems createElement() does work for loading JS files after the page has loaded, which is nice
Try this: Code:
<script type="text/javascript"> <!-- function load_ads(url, appendobj) { ads = document.createElement('script'); ads.src = url; ads.type = 'text/javascript'; document.getElementById(appendobj).appendChild(ads); } load_ads('YOUR_SCRIPT_URL', 'YOUR_APPEND_OBJECT'); --> </script> Code:
load_ads('YOUR_SCRIPT_URL', 'YOUR_APPEND_OBJECT'); |
#9
|
|||
|
|||
Thank you very much Deceptor...
but it doesn't work |
#10
|
||||
|
||||
From what I can tell, the script you pass into it doesn't work for some reason. But I know if i pass a test script it executes fine, there's really nothing more I can think of unfortunately.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|