Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project I have got a "back button" that is calling a javaScript function that remembers the previous url when called.
JavaScript
//back button function
function goBack() { $window.history.back(); }

the url being remembered or being called when the back button is clicked contains an ID and this is ID is used to filter data. The main problem i'm having is that this ID is being returned as a string encoded in html. for example this is the url being called:

//Lookups?$filter=VehicleId%20eq%20%272415%27&

As you can see VehicleId is 2415 in above url, which is also encoded to %20%272415%27&. this in plain text is VehicleId = "2415". This is clashing with my program as my program is expecting an int variable instead of a string.

To resolve this i am trying to de -encode?? from html to make the ID to an int. and i having been looking at this http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_unescape but i still can't figure how to put this in my project.


I am using $location in order to remember the ID in url like so:

JavaScript
if ($location.search().vehicle) {
                           var str = vehicle;
                           var strEsc = unescape(str);
                           vehicle = strEsc;

                         vehicle = $location.search().vehicle;

                       }

To be honest i don't if i am doing this right (which i'm not sure) ..Is any one to help with this please?
Posted

1 solution

Refer: decodeuricomponent[^]
+++++++++++++ part 2 +++++++++++++
page1.html
XML
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Page 1</title>
<script>
function myFunction(){
    var query="page2.html?vechicleid=1234&prev_url="+location.href;
    window.location = query;
}
</script>
</head>
<body>
<button type='button' onClick="myFunction();">Click me</button>
</body>
</html>

page2.html
XML
<!DOCTYPE html>
<html>
<head>
<title>Page 2</title>
</head>
<body>
<script>
   var queryString = decodeURIComponent(window.location.search);
   queryString = queryString.substring(1);
   var queries = queryString.split("&");
   for (var i = 0; i < queries.length; i++)
   {
       document.write(queries[i] + "<br>");
   }
</script>
</body>
</html>
 
Share this answer
 
v3
Comments
1Future 14-Nov-14 5:16am    
Thank you for responding... Do you know how i can get the url before it is triggered?
Peter Leow 14-Nov-14 6:10am    
See sample code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900