www.webdeveloper.com
Results 1 to 14 of 14

Thread: using javascript inside javascript?

  1. #1
    Join Date
    Jul 2007
    Posts
    4

    using javascript inside javascript?

    hello

    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....

    <!-- JAVASCRIPT SCROLLER -->
    <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
    Posts
    104
    Without knowing exactly whats going on, you could probably try something like this:

    Code:
    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
    Location
    Sydney, Australia
    Posts
    7,974
    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.
    Stephen

  4. #4
    Join Date
    Sep 2005
    Posts
    73

    A script inside a Script

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

  5. #5
    Join Date
    Jul 2007
    Posts
    4

    merging or calling functions

    hello

    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
    Posts
    73
    Hi.
    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
    Posts
    4

    example javascript

    hello

    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)

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

    [part2] - outputs html
    <tr>
    <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>


    </tr>


    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
    Location
    Cleveland
    Posts
    579
    js_jaco

    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
    Posts
    73
    Hi.
    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
    Location
    Cleveland
    Posts
    579
    Lazer

    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
    Posts
    73
    Hi
    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
    Posts
    4

    javascript

    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
    Posts
    73
    Well.
    This sure is very interesting project. Ilike projects of this kind!!
    I will check and let you know.

  14. #14
    Join Date
    Sep 2012
    Posts
    2
    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('</td><td>');
    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 ?

    Thanks.

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



Recent Articles