If I set the following up:
<script type="text/javascript" src="https://test.com/abc"></script>
Between the head tags, the code runs when the page starts up. Is there any way of stopping this from running during startup and instead running it using the onclick method from a html button?
Take the javascript in your file and wrap it in a function. You can then assign that function to the onclick attribute of a button.
<button onclick="myFunction()">Click Me</button>
And your script
function myFunction() {
//your existing code goes here
}
Here's a fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With