Can i know if an url is present inside the browser history?
I know that HTML5 have introduced the history API, and infact i'm using it for push states inside urls and memorize it into the history.
I need that for this purpose: i've created a page for personal purpose that performs a scan to a webstore for keep trace of prices, and print results inside mine.
I need to know if from my last visit some prices are changed, and for do this i memorize my last visioned product/price couples as url inside the history
something like www.domain.com/index.php?producName=somename&price=someprice
Nextime i load the page, i need to know if a certain url (www.domain.com/index.php?producName=somename&price=someprice) is present or not inside history, if yes, assign the "visited" value withint the class parameter of the element, if not, i will do other things.
Anyway, in few words, i need to read in some way the browser history, or i can't proceed with my idea.
PS: yes, i know that i could memorize this type inormation inside a file in server side scripting, instead of use history, but for the moment i've designed the project for work essentially client side.
Last edited by American horizo; 04-05-2014 at 01:30 PM.
The short answer: no.
The HTML5 History API is more or less designed to allow users to push urls into the history so while dynamically loading pages, a user can still have the standard expectation of using their browsers forward/back buttons to navigate these dynamic pages. It is not designed to grant access to the actual browser's history and the history object is even further limited by the pages navigated within a current session of that specific tab. For example, If I go to google.com, search for 'hats' then open a result, the history object on this hats page only holds data for google.com and my google search results page. But even then the actual urls are never exposed, only the number of pages in that history session (3) and the ability to navigate those pages.
The history API does allow you to access a user's browser history but it's a lot more limited than what you're after. There used to be a security loophole based on CSS whereby a previously visited website link would change colour, however, it is a few years old and has since been fixed (unless I'm completely mistaken). The only way I can see you doing what you're after and from a client-side approach is if you created your own browser that had next to no history security and the history object stored all of the pages visited no matter the amount.
I wouldn't say you cant proceed with your idea, you just have to re-visit the drawing board, unless you do want to take the route of creating your own browser.
So, can maybe i use one single cookie to store an abnorm string or there are limits of size?
As a last resort, i need to re-design the entire structure of the script, using PHP instead of jquery for access html elemens... For this reason, there exists a library that allow to read elemnt in a simplest way?
For exemple, if inside my PHP code i've a variable in which is stored an html code, can i extract from it single elements with specified classes (such jquery does) farther using regexp ?
Last edited by American horizo; 04-05-2014 at 06:44 PM.
A single cookie can only store up to 4 KB, however, if the data size becomes an issue, then you shouldn't be using cookies for that data.
For your second question, PHP can extract information contained in HTML class attributes. There are built-in functions to read by ID and tagname (i.e. <td>) but not by class. If the same class is always used in the same type of HTML element, then you can read all of those tag names and use string manipulation to get the classes.
Don't forget about localStorage in HTML5. The typical standard limit is 5MB, which I would have to assume should be enough given the type of data you are storing. And expanding on that even further, you could even utilize the Indexed DB API of HTML5 if you care to have a much more structured way or storing your data all while doing it locally.
I think that local storage is perfect for my purpose, thanks
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)