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 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Adding JS to FB or +1 button

    Hi,

    I was trying to add some simple javascript (toggle visibility function of a div) to the FB 'like' button and 'Google +1' button. This to simply create some more visitor interactivity by showing a thank you message for doing so.

    I've tried by just adding 'onclick=' to the element that actually shows the button, with a <a href="#" onlcick="..."> --element--</a> manner, and with a <span> and a <div> element around it.

    Neither of them work. The toggle script is 100% correct (using it actively with <a href="javascript:void(0);" onclick="javascript:toggleVisibility('feedbackform')">feedback</a> ) Of course I made sure the div id had correct name and it is unique for the toggle function.

    Anybody got any ideas on how to go with this?

    JS:
    Code:
    function toggleVisibility(controlId) {
    	if (document.getElementById) { // DOM3 = IE5, NS6
    		var control = document.getElementById(controlId);
    		if(control.style.display == "")
    			control.style.display = "none";
    		else
    			control.style.display = "";        
    	}
    	else {
    		if (document.layers) { // Netscape 4
    			if(document.controlId.display == "")
    				document.controlId.display = "none";
    			else
    				document.controlId.display = "";        
    		}
    		else { // IE 4
    			if(document.all.controlId.style.display == "")
    				document.all.controlId.style.display = "none";
    			else
    				document.all.controlId.style.display = "";        
    		}
    	}
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Netscape 4 and IE4 are long, long obsolete. So is onclick = "javascript:

    Code:
    <script type="text/javascript">
    function Toggle(obj) {
    var Style = document.getElementById(obj).style;
    Style.display = (Style.display == "none") ? "" : "none";
    }
    </script>
    <div id="MyDiv">Content Goes Here</div>
    
    <input type = "button" value = "Toggle" onclick="Toggle('MyDiv')">

    Quizmaster: The five breeds of swan found in the United Kingdom all have plumage of predominantly what colour?
    Contestant: Red

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks, 100% right about that, that is a lot more efficient. However that does not solve the problem with adding extra functionality on click the 'like' button o '+1' button. I'm trying to copy the .js file from google server to my server and then add some code, however just copying the js from google server to my server and then using it does not seem to work so I'm gonna try to work around that..

  • #4
    New Coder
    Join Date
    Aug 2008
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    found a solution for what I wanted. Wrote about it here:
    http://www.stevenvanderpeijl.com/201...r-customers/62

    for anybody who is looking for the answer.

    Best regards,


  •  

    Posting Permissions

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