![]() |
having a chat widget appear (or not!) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: having a chat widget appear (or not!) (/showthread.php?tid=79695) |
having a chat widget appear (or not!) - richb201 - 07-20-2021 I'd like to offer paying customers premium support. I have a support widget that I plan to use on a system called tawk.to. They advise to embed the following code on the page. <!--Start of Tawk.to Script--> <script type="text/javascript"> var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date(); (function(){ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0]; s1.async=true; s1.src='https://embed.tawk.to/5fc604b2a1d54c18d8ef211d/default'; s1.charset='UTF-8'; s1.setAttribute('crossorigin','*'); s0.parentNode.insertBefore(s1,s0); })(); </script> <!--End of Tawk.to Script--> Now in my case I am adding the a few lines of HTML at the bottom of every page (see below). Can I just paste the above script onto that page and expect it to display? <h1>company</h1> <p></p> <a href="https://researchstudytoolkit.tawk.help/category/setting-up-the-research-credit-study-toolkit#company-tab" target="_blank">help on setting up the research study online</a> <br> <br> can I just place the above script here? RE: having a chat widget appear (or not!) - richb201 - 07-20-2021 I managed to get the regular old chat widget working. Now I just need to be able to have that appear only for paying users. I created a flag in the session vars for it. I then tried adding this code. Can I not wrap javascript within a php section? I need to use php to check if the user gets premium support or not. <?php if ($_SESSION['premium_support']==1) { <script type="text/javascript"> var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date(); (function(){ var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0]; s1.async=true; s1.src='https://embed.tawk.to/5fc604b2a1d54c18d8ef211d/default'; s1.charset='UTF-8'; s1.setAttribute('crossorigin','*'); s0.parentNode.insertBefore(s1,s0); })(); </script> } ?> How can I accomplish this? <? ?> RE: having a chat widget appear (or not!) - InsiteFX - 07-20-2021 You need to load the script on startup or it will not load later, best bet would to add it to a div then hide it. After that if they are a paying customer then show the hidden div. RE: having a chat widget appear (or not!) - paliz - 07-21-2021 I used pusher.Io realtime service for notifications and chat communication Pusher. Io has great service and clear documentation , eazy work with it Pusher. Io offers free and perumin plans too RE: having a chat widget appear (or not!) - superior - 07-21-2021 For what version of CodeIgniter are you searching this solution? RE: having a chat widget appear (or not!) - craig - 07-21-2021 You can accomplish this, but you can't just embed Javascript code directly in your PHP code. Code: <?php if ($_SESSION['premium_support']==1): ?> The only thing to make sure of is that the session variable 'premium_support' has a value. |