1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to call Javascript function in the link?

Discussion in 'Joomla' started by richardm55, Jan 4, 2013.

  1. #1
    I would like to use Javascript function to realize adding my website to favourites. Firstly, I don't know how to put this function, in standard web pages there is link in the head section, how to realize that in joomla?
    Secondly, I want to call this function by clicking the link either on text or icon.

    Please help me how to realize that.
     
    richardm55, Jan 4, 2013 IP
  2. evuln.com

    evuln.com Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    <a href="somesite.blabla" onclick="alert('hello')">anchor</a>
    replace alert() by your function
     
    evuln.com, Jan 4, 2013 IP
  3. richardm55

    richardm55 Active Member

    Messages:
    762
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    65
    #3
    What is that text "somesite.blabla"? I want to put function name there with its arguments. How can I put whole function content in joomla then?
     
    richardm55, Jan 4, 2013 IP
  4. richardm55

    richardm55 Active Member

    Messages:
    762
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    65
    #4
    I better explain it by example:
    In standard html there is link <a href="javascript: function_name('Favourite_name', 'my_website_address')">Add to favourite</a>
    And I want to put the javascript function "function_name(arg1,arg2)" somewhere in joomla but I don't know how and where to exactly? Normally in standard html/css I create link to javascript file in the head section, that file containing javascript function, or I could insert that function between script tags also in head section. But how to realize that in joomla which based on php?
     
    richardm55, Jan 4, 2013 IP
  5. richardm55

    richardm55 Active Member

    Messages:
    762
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    65
    #5
    Or maybe there is another solution for this? Maybe I should convert javascript function into php function and to just call php one? But I think it would be a little silly because its better to realize that on client site than to call function placed on server.
     
    richardm55, Jan 4, 2013 IP
  6. hiflyer.vn

    hiflyer.vn Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    you only insert
    <a href="#" id="yourid">yourcontent</a>
    <script type="text/javascript">
    jQuery(document).ready(function($){
    $("yourid").click(function(){
    alert("me"); // you can insert you function here
    })
    }
    </script>
     
    hiflyer.vn, Jan 4, 2013 IP
  7. richardm55

    richardm55 Active Member

    Messages:
    762
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    65
    #7
    Thank you for your help. If I insert this code in place where link is going to be so javascript oode with my java script function will probably land in home section unless joomla do this properly and html part put into home section and javascript into right place.
     
    richardm55, Jan 5, 2013 IP
  8. richardm55

    richardm55 Active Member

    Messages:
    762
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    65
    #8
    Maybe above solution is all right but I didn't and still don't know how to use it. Where am I to supposed to insert that code?
    I have found another solution:
    1) Icon which adds favourite has link <a hef="javascript:addfavourite('Website_name', 'Website_url')">Link_text</a>
    2) In main joomla directory adding file favourite.js with function addfavourite()
    3) In template directory in its subdirectory layouts in file template.php in section <head> adding address to file favourite.js as:<script type="text/javascript" src="favourite.js"></script>
     
    richardm55, May 4, 2013 IP
  9. richardm55

    richardm55 Active Member

    Messages:
    762
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    65
    #9
    I think it is missing closing bracket in this code!!!!!
    jQuery(document).ready(function($){
    $("yourid").click(function(){
    alert("me");
    })
    }
    There is opening bracket after word "ready". Where is its closing one?
     
    richardm55, May 4, 2013 IP