0

I have this code with <button> and I run a script to query information in a database. I would like to make the function start when loading the page without having to use the button, how to do it?

button {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  display: inline-block;
  padding: .625rem 1.25rem;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: .25rem;
  color: #fff;
  border-color: #5e72e4;
  background-color: #5e72e4;
  box-shadow: 0 4px 6px rgba(50, 50, 93, .11), 0 1px 3px rgba(0, 0, 0, .08);
  cursor: pointer;
}
<button onclick="gtaller_modal();" id="gtaller_modal" data-gt-ventana="1">Button Text</button>

<script src="https://gestioo.com/gwidget/js/gtaller_modal.min.js"></script>
<!-- Confiugracion: data-gt-ventana="1" //Ventana nueva (0/1) -->
jiwopene
  • 3,077
  • 17
  • 30

2 Answers2

2

You can use the onload event to start a function when the page has loaded. See onload event.

<body onload="myFunction()">

also you can use javascript code to call your function. See this answer

window.onload=myFunction;
// or
document.onload=myFunction;
// or
window.addEventListener('load', myFunction)
// or
document.addEventListener("DOMContentLoaded", myFunction)
/* last two have more compatibility */

You can define your function anywhere but if you are using expression you must do it before above codes. See javascript function defination

Ali
  • 1,528
  • 1
  • 10
  • 12
Denis G. Labrecque
  • 1,023
  • 13
  • 29
0

Remember to link the script

 <script src="https://gestioo.com/gwidget/js/gtaller_modal.min.js"></script>

Then

<body onload="gtaller_modal();">
bsmith
  • 103
  • 3
  • 10