javascript - Onclick open online chat support - Stack Overflow

I am using a third party chat plugin on my site I just placed its javascript code on my site. The code

I am using a third party chat plugin on my site I just placed its javascript code on my site. The code is:

<script type="text/javascript">
  var __lc = {};
  __lc.license = 1812482;

  (function() {
    var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
    lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc/tracking.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
  })();
</script>

Now I have a image on my site I would like when someone click on that image then chat window should open. How to call this function by clicking on that image.

<img src="click_to_chat.png" onclick=""/>

I am using a third party chat plugin on my site I just placed its javascript code on my site. The code is:

<script type="text/javascript">
  var __lc = {};
  __lc.license = 1812482;

  (function() {
    var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
    lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc./tracking.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
  })();
</script>

Now I have a image on my site I would like when someone click on that image then chat window should open. How to call this function by clicking on that image.

<img src="click_to_chat.png" onclick=""/>
Share Improve this question edited Oct 22, 2013 at 15:28 Smern 19.1k22 gold badges77 silver badges93 bronze badges asked Oct 22, 2013 at 15:09 Sony GSony G 1284 silver badges11 bronze badges 4
  • 1 Thats anonymous function and cannot be called explicitly, if you want to call it then give it a name – Voonic Commented Oct 22, 2013 at 15:11
  • That's an anonymous function that is run when the browser parses the JavaScript. There is no way to "run" that function. – War10ck Commented Oct 22, 2013 at 15:11
  • 1 Did you get in touch with LiveChatInc at all? I assume you are trying out the 30-day trial? Besides, how is this PHP? – MonkeyZeus Commented Oct 22, 2013 at 15:13
  • Question is not clear – Dinesh Babu Commented Aug 18, 2014 at 6:37
Add a ment  | 

3 Answers 3

Reset to default 10

If someone is still wondering this, for me, it works like so:

<button onclick="LC_API.open_chat_window();return false">Open Chat</button>

You need to have the LiveChat script tag loaded by the time you use the varible LC_API

Assuming you're using jquery,

<script type="text/javascript">
  var __lc = {};
  __lc.license = 1812482;

$("#yourImage").one("click",function(){      
    var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
    lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc./tracking.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
  });
</script>

First you need to give the function a name (and I assume not auto-execute it):

function initializeChat() {
    var lc = document.createElement('script'); lc.type = 'text/javascript'; lc.async = true;
    lc.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'cdn.livechatinc./tracking.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(lc, s);
};

Then you can call it any time you'd like:

initializeChat();

For example, you say you want to run this when you click on an image. Something like this:

<img src="someImage" alt="someText" id="chatImage" />
<script type="text/javascript">
    var image = document.getElementById('chatImage');
    image.onclick = function () {
        initializeChat();
    };
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744740994a4591024.html

相关推荐

  • javascript - Onclick open online chat support - Stack Overflow

    I am using a third party chat plugin on my site I just placed its javascript code on my site. The code

    19小时前
    70

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信