0

I have a third party javascript code that should not load when the page is loaded.

So when you click on the "Request more info", only at that time it should load.

I tried with show/hide but seems the script still loads when I refresh the page.

My HTML is here

 <button onclick="PodiumWebChat.open()">
  Open chat

And Javascript is:

<div id="divscript" style="display: none;"><script defer src="https://connect.abc.com/widget.js#API_TOKEN=c0726ce52f4a" id="podium-widget" data-api-token="c0726ce52f4a"></script></div>
user580950
  • 3,558
  • 12
  • 49
  • 94

1 Answers1

0
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>

<input type="button" id="RequestADemo" onClick="$('#default').click()" value="Request A Demo" />
<div id="test"></div>
<script type="text/javascript">

$(document).ready(function(){
  // this code will run when the document has loaded
  // and all elements are in place

  $("#RequestADemo").click(function(){
    // this code will be run when the user clicks on
    // the button we created above

    $('#default').click(); // this calls the click event on #default

    //alert('Finished'); // now it is finished
        var tag = '<script defer src="https://connect.abc.com/widget.js#API_TOKEN=c0726ce52f4a" id="podium-widget" data-api-token="c0726ce52f4a"><\/script>';
       $('#test').append(tag); //testing

  }); // close the click handler on #RequestADemo

}); // close the document.ready code block.

</script>
user580950
  • 3,558
  • 12
  • 49
  • 94