Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:15:31+00:00 2026-06-15T18:15:31+00:00

I’m tasked to execute specific page javascript on pagechange in Jquery Mobile (Such as

  • 0

I’m tasked to execute specific page javascript on pagechange in Jquery Mobile (Such as geolocate the user on one page or show a Google map on another page)

Its really not clear how to execute javascript after a pagechange but i’m almost there, i was able to use

$(document).bind('pageinit', function(event){

    loadGmaps();
    geolocate();

});

But the problem is that this code executes on each page change/page init and if i’m not on a page that has a #map tag, it just executes code for nothing. Worst? Jquery keeps pages loaded in memory but hides them. So if i change page, it can reload the map 16 times in a row for nothing.

I’m really confused as to how you are supposed to bind specific page javascript in a jquery mobile loaded page. I’m lurked all around the web and i’m sure i’m not the only one looking for that specific trick…

Thanks


EDIT

I changed my code to reflect Jasper’s solution, and it works fine except for the geolocation:

$(document).on('pageinit', '#wp-post-id-70', function(event){
    geolocate();
});
$(document).on('pageinit', '.wp-post-type-spa', function(event){
    loadGmaps();
});

The maps load fine on each page i visit that is a spa, but when i load a spa page from a fresh load, if i click on the logo to go back to the home page, it loads the home page and then fires the “geolocate” function but nothing happens in terms of geolocation:

function geolocate()
{
    if (navigator.geolocation) { 
        navigator.geolocation.getCurrentPosition(
            function(position){
                $('#near_spa').load('?latitude='+position.coords.latitude.toString()+'& longitude='+position.coords.longitude.toString()+' #near_spa > *');
            }
        );
    }else{ 
        alert('Votre navigateur ne supporte pas la géolocalisation ou refuse l\'accès aux données de localisation');
    }
}

The code really goes up to the navigator.geolocation.getCurrentPosition, it gets called but then pffff, nothing. If i reload the home page manually with F5, i now get the geolocation request…


EDIT

Never mind that “map” loads fine on each page, it doesn’t anymore, probably me and my brain being too tired…

Therefore, the

$(document).on('pageinit', '.wp-post-type-spa', function(event){
    loadGmaps();
});

Doesn’t load the maps anymore at all and yes, i verified, the pages do feature a wp-post-type-spa class…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:15:32+00:00Added an answer on June 15, 2026 at 6:15 pm

    If you have code that only runs once per pseudo-page, then use the pageinit event, which only runs once every time a pseudo-page is added to the DOM.

    You can also target specific pseudo-pages in your bind call:

    $(document).on('pageinit', '#some-map-page', function(event){
    
        loadGmaps();
        geolocate();
    
    });
    

    This will only run when the pageinit event fires on an element with the ID of some-map-page. You could for example add a class to each pseudo-page element where you want to run the map code:

    <div data-role="page" id="some-map-page" class="map-page">...</div>
    

    Which would work with the following event binding:

    $(document).on('pageinit', '.map-page', function(event){
    
        loadGmaps();
        geolocate();
    
    });
    

    Notice that I’m using .on() as a delegated event handler, which is very useful when using jQuery Mobile as you can’t ever be sure when a pseudo-page exists in the DOM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to show the soap response to UIWebview.. my soap response is, <p><img

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.