Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: call a function

  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    97
    Thanks
    2
    Thanked 0 Times in 0 Posts

    call a function

    Hello, if in a webpage is included a javascript file (for example code.js) can I from my browser call a function contained in code.js and will it works correctly?
    I'm not meaning that the function is called in the page with or without a link to click, but it is only in code.js!

    Thank you!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,893
    Thanks
    79
    Thanked 4,421 Times in 4,386 Posts
    You mean you want to call it from the address bar of the browser??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    97
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    You mean you want to call it from the address bar of the browser??
    Not compulsorily on the address bar, just know if it is possible and there is a method to do that...

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,893
    Thanks
    79
    Thanked 4,421 Times in 4,386 Posts
    I'm lost.

    If you don't care about doing it from the address bar, then the only other way is to have code in that HTML page that calls it. Which you certainly can do. But I don't feel that's what you mean.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder riptide's Avatar
    Join Date
    Jan 2007
    Posts
    143
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Do you mean onload?

  • #6
    New Coder
    Join Date
    Nov 2011
    Posts
    97
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I mean a page includes fun.js and inside fun.js there is a function that do something but it isn't called in the page.
    Can I call it from my browser and it will work?

    Thanks!

  • #7
    New Coder
    Join Date
    Jan 2012
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    So you are saying that in your JS file there are say two functions, yet your HTML file only calls one of the functions but you want the 2nd function to be ran as well but not from code that is in the HTML file.

    I'm sure that you can get a 2nd HTML file to run the 2nd function in your JS file.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You should be able to call that function either from the address bar or from any JavaScript you have attached to the browser yourself.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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