how to pass values from one html page to the other html page in PHONEGAP?

此生再无相见时 提交于 2019-12-24 12:37:25

问题


i have searched for this answer and i got 2 sort of replies,which i found i could implement it.

they are..

window.location.href=href='2ndpage.html?var id=results.rows.item(1).id';

*results.rows.item(1).id-this the value i am getting it from the database---it would be the value of the id of the element in the DB.

to get the value,i implemented this code..

 function onDeviceReady() 
    {var db =  window.sqlitePlugin.openDatabase("Database", "1.0", "Database",1000000); 
     console.log("processing onDeviceReady");
     db.transaction(getParameter,queryDB,errorCB);  
    }           

    function getParameter(paramName) 
    {   console.log("processsinggg parameter loop ");
    var searchString = window.location.search.substring(1),
        i, val, params = searchString.split("&");

         for (i=0;i<params.length;i++) {
                val = params[i].split("=");
            if (val[0] == paramName) {
            return unescape(val[1]);
        }
    console.log("valueeesss: "+val[1]);

  }return null;
}

it process till this loop and stops... thinking i havent called the other functions..i called queryDB();

when it processed queryDB in the code

function queryDB(tx) 
{       tx.executeSql('SELECT * FROM table_name', [], querySuccess, errorCB);
        console.log("processing queryDB");
}

it says as tx is not defined..whereas its just a parameter

i tried printing the output...o/p was..

results.rows.item(1).id

which i found difficult implementing it...probably could be because of my mistake too..but....

the other method i tried was the FORM method

<form name="2ndpart"  method="post">
id: <input type="hidden" name="id">
<input type="submit" value="results.rows.item(0).id">
</form> 

and in the second page,i gave

function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(m,key,value) {
    vars[key] = value;
});
return vars;

}

it did not go the 2nd page it self..as it said was not a function.

which is the right method and the easiest to implement?


回答1:


This is how we pass values from one html to another html pages in PHONEGAP

        function test()
        {
            window.location.href="index.html?var id=1";
        }

        <div id="test"><img src="img/test.png" onClick="test()"/></div>



回答2:


In addition to URL param, you can also set the localStorage, sessionStorage, or cookie. In a single page application, you can just set some variable.



来源:https://stackoverflow.com/questions/16120644/how-to-pass-values-from-one-html-page-to-the-other-html-page-in-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!