vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Simple javascript code doesn't work (https://vborg.vbsupport.ru/showthread.php?t=199900)

FatalBreeze 12-27-2008 01:21 PM

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.

Marco van Herwaarden 12-27-2008 02:02 PM

Is that element id correct?

FatalBreeze 12-27-2008 02:14 PM

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.

Deceptor 12-27-2008 04:06 PM

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>


Marco van Herwaarden 12-27-2008 04:19 PM

Still using both "navbar" and "navabr" as id.

Deceptor 12-27-2008 04:47 PM

Never saw that typo, thanks Marco :)

FatalBreeze 12-27-2008 05:19 PM

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?

Deceptor 12-27-2008 05:58 PM

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 :)

FatalBreeze 12-27-2008 06:46 PM

Thank you very much Deceptor...
but it doesn't work :(

Deceptor 12-27-2008 07:09 PM

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.


All times are GMT. The time now is 10:21 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02453 seconds
  • Memory Usage 1,733KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete