Results 1 to 14 of 14

Thread: using javascript inside javascript?

  1. #1
    Join Date
    Jul 2007

    using javascript inside javascript?


    i am having the following problems I am using a news ticker script I have found, but the content is also a script driven source so for example:

    so i want to use javascript inside javascript but i cant use <script> inside an already <script> tag. If this doesnt make sense please let me know....

    <script type="text/javascript">

    * Fading Scroller- Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code

    var delay = 2000; //set delay between message change (in miliseconds)
    var maxsteps=30; // number of steps to take to change from start color to
    fcontent[0]="<span class='tickerText'>I WANT TO PUT JAVASCRIPT IN HERE for example <script src="http://www.somedomain.com/somescript.js"</span>";

  2. #2
    Join Date
    Jun 2007
    Without knowing exactly whats going on, you could probably try something like this:

    fcontent[0] = "<span class='tickerText'><scr" + "ip" + "t src='http://www.domain.com/jsfile.js'></sc" + "rip" + "t></span>";
    I think you need to break up the script tag (I did it into 3rds for no apparent reason, I think splitting it would do the job).

  3. #3
    Join Date
    Mar 2005
    Sydney, Australia
    You don't need to split the script tag up into sections, you just need to escape the / as \/ so that the browser doesn't read <\/script> as the end of the current script.

  4. #4
    Join Date
    Sep 2005

    A script inside a Script

    You can not create a script inside a script.
    you can merege both files (*.js) into a single file.
    you can call one script from another by calling it's function.
    you can create a "child" script tag in the body but it does not always work well...

  5. #5
    Join Date
    Jul 2007

    merging or calling functions


    have tried the first solution but could not get it to work, I liked the suggestion of combining the javascript only problem is I have no control over the script I am calling in because I get it from an external source. So I cant use the function only the src tag is available to me.

    so lets say I have my .js file i have function:

    // function call external
    function callExternal() {
    <script src="http://link_from_external site"></script>

    function scrollingText() {
    ticker.text[0] = callExternal1();

    does this clarify my problem?
    // end function

    I have used flash with the xml feed to get around the problem but would still like to understand how to get around this.

  6. #6
    Join Date
    Sep 2005
    If the script is from another site, not for RSS feed, you can very easy DOWNLOAD the file by typing in the full URL in the address line and save it and upload it to your site.
    If it is for RSS feed, it can still be done but must be checked first.

  7. #7
    Join Date
    Jul 2007

    example javascript


    there are two methods they sent me to use, one is the link to the xml file (which I used to create the flash file)

    the other is an example script: (this I put in the head)

    <SCRIPT src="http://www.somedomain.com/mandatory.php?currency=ZAR"></SCRIPT>

    [part2] - outputs html
    <td style="font-size:1px;"><!--CashSplash--><SCRIPT src="http://www.somedomain.com/getFile.php?progid=1&id=644&pw=644&cbox=0&showlogo=no"></SCRIPT></td>


    I see what you meant by typing in the url of the mandatory script I see the function but by downloading it and putting it in the function I will lose the updating? meaning its a script that continuosly update values.

    I guess I could write a html / xml / javascript function that retrieves the xml and then write it to an array and then use it with my ticker? Is that the correct way?

  8. #8
    Join Date
    Sep 2006

    I need to understand one thing, is this javascript given to you from the service or is it an include script you were provided for this service to work. Then We can go from there.

  9. #9
    Join Date
    Sep 2005
    If they give you link to the XML file, I can give a PHP code to read and use it.
    I prefer PHP over javascript when possible.
    But I don't really see what is the problem in running the first script, and then running the second calling the function from the first?
    The only thing/s you MUST know is the variables names so that you can retrive them and use them in the other script.

  10. #10
    Join Date
    Sep 2006

    What I have come across is that you include some javascipt on your site which creates an instance of the news website info on your page. It is probably not and xml feed such as rss because if you have images or text to format it would be dificult to get this done on a browser standard way so to speek. If there is indeed some javascript in the feed you are wise to put the local code that interacts with the news elements at the bottom of the page so that to make sure the timing of the news and the page load is correct so you do not get error from elements or functions not being loaded in the browser on time. Hope that makes sense.

  11. #11
    Join Date
    Sep 2005
    So one script is from Dynamic Drive running from YOUR web site (I guess), and the other runing from another EXTERNAL web site?
    What is the connection between them both? how do the interact?

  12. #12
    Join Date
    Jul 2007


    the connection between the two is that I am using the ticker script from dynamic drive and the content of each individual ticker is a seperate javascript which I receive as <script language="javascript" src="http://www.domain.co.za/feed.php?id=1"></script>

    just to explain what the remote javascript does, its an online moblie gambling jackpot updater. So it updates the html on real time showing the value of the jackpots.

    also I can not use php since the website is going to be hosted on a IIS server, probably running as ASP.NET.

    I have already made this thing work using flash and the xml feed, because of all the complexity involved with combining javascript but was just curious on how to combine javascript inside javascript.

    I do agree that putting the functions of the source (external javascript) would be a much smarter idea but would that still work since the javascript pulls values from another website (jackpot values) and updates it.

  13. #13
    Join Date
    Sep 2005
    This sure is very interesting project. Ilike projects of this kind!!
    I will check and let you know.

  14. #14
    Join Date
    Sep 2012
    If the regular code for creating a Twitter button is, say:

    <a href="https://twitter.com/twitter" class="twitter-follow-button" data-show-count="false">Follow @twitter</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

    Then how exactly would input this code into a header.js file?

    I have gone this far:

    document.write('<a href="https://twitter.com/twitter" class="twitter-follow-button" data-show-count="false">Follow @twitter');
    document.write('<function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs")><br>');

    but all that is showing in the header is follow@twitter as a hyperlink, and the twitter BUTTON is not rendering. How should I input the javascript code inside the header.js ?


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.13524 seconds
  • Memory Usage 2,995KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (14)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (14)postbit
  • (14)postbit_onlinestatus
  • (14)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates