title: jQuery - change a script to load on page load
body: <p>I have a geo-location script that triggers when a user hits the "Give me directions" button ".get-directions", this works fine.</p>
  
  <pre><code>&lt;div class="dirBtn"&gt;10 Street Road, Suburb, Country&lt;/div&gt;
  &lt;!-- css --&gt;
  &lt;style&gt;
  p.warning { color: red; }
  input.manual-location { width: 95%; font-size: 1.2em; padding: 5px; }
  .no-geolocation { display: none; }
  .get-directions { background: #000; padding: 8px 13px; color: #ffffff; font-size: 16px; font-weight: bold; border-radius: 6px; margin: 0 auto 0 auto; text-decoration: none; clear: both; display: block; text-align: center; cursor:pointer; width:80%; }
      .get-directions:hover { text-decoration:none;  color: #ffffff; background:#333; font-weight: bold; }
  .dirBtn { visibility:hidden; }
  &lt;/style&gt;
  
  &lt;!-- javascript --&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script&gt;
  
  var gmap = $('.dirBtn').text();
  
  
  $(document).ready(function () {
  
      var startingLocation;
      var destination = gmap.replace(/\s/g,"+")
  
      $('a.get-directions').click(function (e) {
          e.preventDefault();
  
          // check if browser supports geolocation
          if (navigator.geolocation) {
  
              // get user's current position
              navigator.geolocation.getCurrentPosition(function (position) {
  
                  // get latitude and longitude
                  var latitude = position.coords.latitude;
                  var longitude = position.coords.longitude;
                  startingLocation = latitude + "," + longitude;
  
                  // send starting location and destination to goToGoogleMaps function
                  goToGoogleMaps(startingLocation, destination);
  
              });
          }
  
              // fallback for browsers without geolocation
          else {
  
              // get manually entered postcode
              startingLocation = $('.manual-location').val();
  
              // if user has entered a starting location, send starting location and destination to goToGoogleMaps function
              if (startingLocation != '') {
                  goToGoogleMaps(startingLocation, destination);
              }
                  // else fade in the manual postcode field
              else {
                  $('.no-geolocation').fadeIn();
              }
  
          }
  
          // go to Google Maps function - takes a starting location and destination and sends the query to Google Maps
          function goToGoogleMaps(startingLocation, destination) {
              window.location = "https://maps.google.com/maps?saddr=" + startingLocation + "&amp;daddr=" + destination;
          }
  
      });
  
  });
  
  
  &lt;/script&gt;
  &lt;div class="no-geolocation"&gt;
  &lt;p class="warning"&gt;Your browser does not support Geolocation. Please enter             your postcode and click the button again.&lt;/p&gt;
  &lt;input type="text" placeholder="Enter postcode or address" class="manual-location"&gt;
  &lt;/div&gt;
  &lt;a class="get-directions show" target="_blank"&gt;Give me directions&lt;/a&gt;
  </code></pre>
  
  <p>What I want to do is put the "Give me directions" button/link on a different page:</p>
  
  <p>Example.</p>
  
  <pre><code>&lt;a href="pagename/pagewiththescript" class="get-directions show" target="_blank"&gt;Give me directions&lt;/a&gt; 
  </code></pre>
  
  <p>And modify the script to launch straight away when the page loads, because I didn't write the geo-location script I just need a hand converting it from an "on click" to a "page load".</p>
  
  <p>I hope I explained that clear enough, feel free to ask any questions.</p>