In my project I have got a "back button" that is calling a javaScript function that remembers the previous url when called.

      //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:

        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?

Recommended Answers

All 2 Replies

I used

a=unescape('Lookups?$filter=VehicleId%20eq%20%272415%27&');
alert(a);

and got back

Lookups?$filter=VehicleId eq '2415'&

Do you need more?

Simply use replace() function with regex. The returned value from window.history.back() is a string. You simply look up for ASCII table and use the "Hex" number. Then add the percentage symbol in the front - i.e. white space is %20. Therefore, your current string "VehicleId%20eq%20%272415%27&" should be "VehicleId eq '2415'&"...

var str = "VehicleId%20eq%20%272415%27&";
var decstr = str.replace(/%20/g, " ");
// decstr -> "VehicleId eq %272415%27&"
decstr = str.replace(/%27/g, "'");
// decstr -> "VehicleId eq '2415'&"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.