Window.location.hash always shows a blank

In my phonegap application I updated my data for this, I have the following code in which I got the value window.location.hash (* indicate the error line) will be empty.

 function init() { $("#homePage").live("pageshow", function() { getDatas(); }); $("#editPage").live("pageshow", function() { ***var loc = window.location.hash;*** alert("loc" + loc); if(loc.indexOf("?") >= 0) { var qs = loc.substr(loc.indexOf("?")+1, loc.length); var detailId = qs.split("=")[1]; $("#editFormSubmitButton").attr("disabled", "disabled"); dbShell.transaction(function(tx) { tx.executeSql("select id,name,age,city,occupation from nameDetail where id=?", [detailId], function(tx, results) { $("#mId").val(results.rows.item(0).id); $("#mName").val(results.rows.item(0).name); $("#mAge").val(results.rows.item(0).age); $("#mCity").val(results.rows.item(0).city); $("#mOccupation").val(results.rows.item(0).occupation); $("#editFormSubmitButton").removeAttr("disabled"); }); }, dbErrHandler); } else { alert("empty"); $("#editFormSubmitButton").removeAttr("disabled"); } }); } function getDatas() { dbShell.transaction(function(tx) { tx.executeSql("select id,name,age,city,occupation,date from nameDetail order by date desc", [], renderEntries, dbErrHandler); }, dbErrHandler); } function renderEntries(tx, results) { if (results.rows.length == 0) { $("#mainContent").html("<p>Don't have any Details</p>"); } else { var s = ""; for (var i = 0; i < results.rows.length; i++) { s += "<li><a href='addEdit.html?id="+results.rows.item(i).id + "'>" +results.rows.item(i).name + "</a></li>"; alert("" + s); } //alert(S); $("#noteTitleList").html(s); $("#noteTitleList").listview("refresh"); } } 

Index.html:

 <!DOCTYPE HTML> <html> <head> <meta name="viewport" content="width=320; user-scalable=no" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <title>Names</title> <link href="css/jquery.mobile-1.0rc1.min.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" charset="utf-8" src="cordova.js"></script> <script src="js/jquery-1.6.4.js"></script> <script src="js/jquery.mobile-1.0rc1.min.js"></script> <script src="js/index.js"></script> </head> <body onload="init();"> <div data-role="page" id="homePage"> <div data-role="header"> <h1>Names</h1> </div> <div data-role="content" id="mainContent"> <ul data-role="listview" id="noteTitleList"></ul> </div> <div data-role="footer" class="ui-bar"> <a href="addEdit.html" data-role="button" data-icon="plus">Add Note</a> </div> </div> </body> </html> 

and addEdit.html:

 <div data-role="page" id="editPage"> <div data-role="header"> <h1>Details</h1> </div> <div data-role="content"> <form id="addEditForm" method="post"> <input type="hidden" name="mId" id="mId" value=""> <div data-role="fieldcontain"> <label for="mName">Name</label> <input type="text" name="mName" id="mName"/> </div> <div data-role="fieldcontain"> <label for="mAge">Age</label> <input name="mAge" id="mAge"/> </div> <div data-role="fieldcontain"> <label for="mCity">City</label> <input name="mCity" id="mCity"/> </div> <div data-role="fieldcontain"> <label for="mOccupation">Occupation</label> <input name="mOccupation" id="mOccupation"/> </div> <div data-role="fieldcontain"> <input type="submit" id="editFormSubmitButton" value="Save Note"> </div> </form> </div> <div data-role="footer" class="ui-bar"> <a href="index.html" data-role="button" data-icon="home">Return Home</a> <input type="button" data-role="button" id="sync" name="sync" value="Sync" data-icon="arrow-d"/> </div> </div> 

how to solve this problem, help solve this problem ...

EDIT:

The problem is solved using this. decision link

+7
javascript jquery cordova
source share
2 answers

I got a solution using the following method

 var loc = $(location).attr('href'); if (loc.indexOf("?") >= 0) { var url = loc.substr(loc.indexOf("?") + 1, loc.length); listId = url.split("=")[1]; 

it will be useful for someone like me.

I solved the problem using this Refer link

+2
source share

I assume this javascript works the same as javascript in a traditional browser here.

Judging by the comments in the code, it looks like you expect the hash to contain a query string, maybe?

The hash contains only that after the hash in the URL

eg,

www.this.com/apage.html?firstval=value&anothervalue=45#locationinpage

in this url

window.locationhash will be equal to "#locationinpage"

but

window.locaton.search will be equal to "? firstval = value & anothervalue = 45"

That is: the query string, excluding the part after the hash

maybe you need window.locaton.search as well?

+2
source share

All Articles