www.webdeveloper.com
Results 1 to 7 of 7

Thread: Can i know if an url is present inside the browser history?

  1. #1
    Join Date
    Jan 2013
    Posts
    84

    Question 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.

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    862
    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.

    A user's browsing history will likely never be openly exposed by javascript, HTML or any other language as it's a privacy/security issue. On a related note you actually are given very limited control over CSS when setting the a:visited properties for a similar reason. Since the :visited pseudo selector is directly linked to a user's browsing history the CSS properties allowed is drastically reduced to prevent any potential exposure of previously visited pages.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  3. #3
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    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.

  4. #4
    Join Date
    Jan 2013
    Posts
    84
    bad story.
    I also thought to use cookies... But memorizing a lot of cookie, after i loaded the page once, next time it retrieve me a Bad request error, i assume due to the large number of cookie generated

    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.

  5. #5
    Join Date
    Feb 2014
    Location
    Canada
    Posts
    155
    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.

    PHP is server-side, meaning it will have access to data sent between the webpage and the server. Generally, JavaScript or jQuery are used to read the information from the HTML elements and send it to the server. There are different ways to send it to the server depending on how you want the website to behave.

    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.

  6. #6
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    862
    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.
    "Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"

  7. #7
    Join Date
    Jan 2013
    Posts
    84
    I think that local storage is perfect for my purpose, thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles