Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-27-2008, 01:21 PM
FatalBreeze FatalBreeze is offline
 
Join Date: Apr 2004
Location: Haifa - Israel
Posts: 163
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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>
(I put this in footer, and the div is in navbar)

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.
Reply With Quote
  #2  
Old 12-27-2008, 02:02 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Is that element id correct?
Reply With Quote
  #3  
Old 12-27-2008, 02:14 PM
FatalBreeze FatalBreeze is offline
 
Join Date: Apr 2004
Location: Haifa - Israel
Posts: 163
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 12-27-2008, 04:06 PM
Deceptor's Avatar
Deceptor Deceptor is offline
 
Join Date: Dec 2008
Location: England
Posts: 514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Reply With Quote
  #5  
Old 12-27-2008, 04:19 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Still using both "navbar" and "navabr" as id.
Reply With Quote
  #6  
Old 12-27-2008, 04:47 PM
Deceptor's Avatar
Deceptor Deceptor is offline
 
Join Date: Dec 2008
Location: England
Posts: 514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Never saw that typo, thanks Marco
Reply With Quote
  #7  
Old 12-27-2008, 05:19 PM
FatalBreeze FatalBreeze is offline
 
Join Date: Apr 2004
Location: Haifa - Israel
Posts: 163
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #8  
Old 12-27-2008, 05:58 PM
Deceptor's Avatar
Deceptor Deceptor is offline
 
Join Date: Dec 2008
Location: England
Posts: 514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Change:
Code:
load_ads('YOUR_SCRIPT_URL', 'YOUR_APPEND_OBJECT');
For the url, use the URL to the js file, as for "YOUR_APPEND_OBJECT", it would be: navbar_720x90
Reply With Quote
  #9  
Old 12-27-2008, 06:46 PM
FatalBreeze FatalBreeze is offline
 
Join Date: Apr 2004
Location: Haifa - Israel
Posts: 163
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much Deceptor...
but it doesn't work
Reply With Quote
  #10  
Old 12-27-2008, 07:09 PM
Deceptor's Avatar
Deceptor Deceptor is offline
 
Join Date: Dec 2008
Location: England
Posts: 514
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 06:20 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08583 seconds
  • Memory Usage 2,254KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete