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 7639849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:31:41+00:00 2026-05-31T08:31:41+00:00

I have two pages: index.html and main.html When i set the main.html page to

  • 0

I have two pages: index.html and main.html

When i set the main.html page to be the default page of my app, the java script works, but when I set the index.html to be the main one, after the redirect, the javascript on the main.html just stops working.

here is the HTML of the two pages:

index.html

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>      

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>
</title>
<link rel="stylesheet" href="jquery.mobile-1.0.1/jquery.mobile-1.0.1.min.css" />
<style>
    /* App custom styles */
</style>
<script src="jquery.mobile-1.0.1/jquery.min.js"></script>
<script src="jquery.mobile-1.0.1/jquery.validate.min.js"></script>
<script src="jquery.mobile-1.0.1/jquery.mobile-1.0.1.min.js"></script>
<script>

$.mobile.allowCrossDomainPages = true; 
$.mobile.ajaxLinksEnabled = false; 

 function onLoad(){
    document.addEventListener("deviceready", onDeviceReady, true);
 }
 function onDeviceReady(){
    // request the persistent file system
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, null);
 }


function onSuccess(fileSystem) {       
    fileSystem.root.getFile("kuapodata.xml", null, gotMe, failFile);
}


// se o arquivo não existir
 function failFile(error) {
    $("#formLogin").show();
 }


// se o arquivo existir
function gotMe(fileEntry) {
    $.mobile.changePage("main.html", null, false, false);       
}



</script>
</head>
<body onload="onLoad();">

   <div data-role="page" id="page1">
        <div data-theme="a" data-role="header">
            <h3>
                Header
            </h3>
        </div>
        <div data-role="content" id="formLogin">
            <form id="loginFrm">
                <div data-role="fieldcontain">
                    <fieldset data-role="controlgroup">
                        <label for="textinputEmail">
                        </label>
                        <input id="textinputEmail" placeholder="email" value="" type="email" />
                    </fieldset>
                </div>
                <div data-role="fieldcontain">
                    <fieldset data-role="controlgroup">
                        <label for="textinputPassword">
                        </label>
                        <input id="textinputPassword" placeholder="senha" value="" type="password" />
                    </fieldset>
                </div>
                <input value="entrar" type="submit" />
            </form>
        </div>

    </div>


<script>
var xml;



function gotFS(fileSystem) {
    fileSystem.root.getFile("kuapodata.xml", {create: true, exclusive: false}, gotFileEntry, fail);
}

function gotFileEntry(fileEntry) {
    fileEntry.createWriter(gotFileWriter, fail);
}

function gotFileWriter(writer) {
         writer.write(xml);
}

function fail(error) {
    alert(error.code);
}



// ao fazer o login
$("form").submit(function() {
    // chama função que valida usuário
    ValidateUser();
    return false;
});


// verifica se o usuário existe
function ValidateUser(email, password) {
    $.ajax({
    type: 'POST',
        url: 'http://********/oauth.aspx',
        data: "email=" + $("#textinputEmail").val() + "&password=" +  $("#textinputPassword").val(),
        success: function(data) {
            // se o usuário existir
            if (data != "false") {
                xml = data;

                // cria o arquivo xml se ainda não existir
                window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);

                // muda o usuário de  página
                $.mobile.changePage("main.html");
            }
            else {
                alert("Dados inválidos. Tente novamente.");
            }
        }
    });
}

</script>

 </body>
 </html>

main.html

    <!DOCTYPE HTML>
<html>
  <head>
        <title>PhoneGap</title>


    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <link rel="stylesheet" href="jquery.mobile-1.0.1/jquery.mobile-1.0.1.min.css" />
    <style>
        /* App custom styles */
    </style>
    <script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>  
    <script src="jquery.mobile-1.0.1/jquery.min.js"></script>
    <script src="jquery.mobile-1.0.1/jquery.validate.min.js"></script>
    <script src="jquery.mobile-1.0.1/jquery.mobile-1.0.1.min.js"></script>

    <script>

$(document).ready(function() {
   alert("yesss");
});





  </script>
  </head>
  <body>

       <div data-role="page" id="page1">
            <div data-theme="a" data-role="header">
                <h3>
                    Header
                </h3>
            </div>
            <div data-role="content" id="main">

            </div>

        </div>


  </body>
</html>
  • 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-05-31T08:31:43+00:00Added an answer on May 31, 2026 at 8:31 am

    jQuery Mobile pulls in remote pages via AJAX. When it does this, it only pulls in the first data-role="page" element it finds. This means that anything outside the data-role="page" element is discarded.

    The best work-around is to put all of your app’s JS into a custom.js file and include it in the head of every page, this way all the code for your site is always available (to do this you will need to use event delegation).

    You can also put the JS for each page inside the data-role="page" element so it is grabbed by jQuery Mobile and not just discarded:

       <div data-role="page" id="page1">
            <script>
                alert('hello');
            </script>
            <div data-theme="a" data-role="header">
                <h3>
                    Header
                </h3>
            </div>
            <div data-role="content" id="main">
    
            </div>
    
        </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

1) We have a page index.html with blocks: <body> <div id=action1>One</div> <div id=action2>Two</div> <div
Here is my set up... I have two pages, index.html and cart.html. I have
I have a simple jQueryMobile index.html page. Within that I have two pages using
I have two pages that inherit from one master page, First.aspx or second.aspx. Navigation
lets say i have two pages links.html & contents.php ... first page contains only
Let's say that I have two html pages that are identically designed, but have
I have two partial views on my main index page with a filter dropdown.
I have two web pages which work basically the same, code-wise, but one of
I have two pages, on the first page after an event happens I change
I have two pages. First one we open with $_POST variables in its url,

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.