Rectangle 27 17

window.location.reload(true)
ctrl+F5

But does that really ignore cached versions of the files of that location?

jquery - clear browser cache and history via javascript and load lates...

javascript jquery
Rectangle 27 17

window.location.reload(true)
ctrl+F5

But does that really ignore cached versions of the files of that location?

jquery - clear browser cache and history via javascript and load lates...

javascript jquery
Rectangle 27 24

Just add the autocomplete attribute

<input type="text" autocomplete="off" />

jquery - Javascript: Prevent browser to display input history for a fi...

javascript jquery
Rectangle 27 24

Just add the autocomplete attribute

<input type="text" autocomplete="off" />

jquery - Javascript: Prevent browser to display input history for a fi...

javascript jquery
Rectangle 27 9

There are other ways to prevent a JavaScript file (or other files) from being cached.

Simply append some dummy parameters to the end of the url. For example -

http://www.yourCoolSite.com/resources/js/main.js?r=SOME_RANDOM_VALUE

You would optimally do this on the server side. In PHP, this would look something like this -

echo "http://www.yourCoolSite.com/resources/js/main.js?r=".time();

Using the time() function, we append the current epoch timestamp to the URL and therefore guarantee* that the file will appear different to the browser each time.

.htaccess may be cleaner, but this works when that isn't an option.

Or instead of SOME_RANDOM_VALUE you could append a hash of the file, this way, it does only get updated when there is something new.

@mrm - that's a great tip! You should add your own answer giving an example...

Perhaps slightly off-topic, but could you explain why it is only until 2038? Will the data type overflow in 2038 because too much seconds have past since 1/1/1970?

@116 - Pretty much :P The 2038 "problem" is pretty much just another Y2K bug ;)

jquery - clear browser cache and history via javascript and load lates...

javascript jquery
Rectangle 27 9

There are other ways to prevent a JavaScript file (or other files) from being cached.

Simply append some dummy parameters to the end of the url. For example -

http://www.yourCoolSite.com/resources/js/main.js?r=SOME_RANDOM_VALUE

You would optimally do this on the server side. In PHP, this would look something like this -

echo "http://www.yourCoolSite.com/resources/js/main.js?r=".time();

Using the time() function, we append the current epoch timestamp to the URL and therefore guarantee* that the file will appear different to the browser each time.

.htaccess may be cleaner, but this works when that isn't an option.

Or instead of SOME_RANDOM_VALUE you could append a hash of the file, this way, it does only get updated when there is something new.

@mrm - that's a great tip! You should add your own answer giving an example...

Perhaps slightly off-topic, but could you explain why it is only until 2038? Will the data type overflow in 2038 because too much seconds have past since 1/1/1970?

@116 - Pretty much :P The 2038 "problem" is pretty much just another Y2K bug ;)

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

jquery - clear browser cache and history via javascript and load lates...

javascript jquery
Rectangle 27 25

They were all quite hard to setup, I did get jQuery.history working but it still had problems with IE7. So I changed to BBQ and it worked fine across all our target browsers (IE6, IE7, IE8, Fx3).

So I recommend the jQuery BBQ plugin.

Edit: here's a blog post I just wrote which demonstrates jQuery BBQ with cascading dropdowns.

javascript - What's the best library to do a URL hash/history in JQuer...

javascript jquery ajax fragment-identifier hashchange
Rectangle 27 25

They were all quite hard to setup, I did get jQuery.history working but it still had problems with IE7. So I changed to BBQ and it worked fine across all our target browsers (IE6, IE7, IE8, Fx3).

So I recommend the jQuery BBQ plugin.

Edit: here's a blog post I just wrote which demonstrates jQuery BBQ with cascading dropdowns.

javascript - What's the best library to do a URL hash/history in JQuer...

javascript jquery ajax fragment-identifier hashchange
Rectangle 27 4

Fiddle with example code: http://jsfiddle.net/koenpunt/pkAz7/1/

// First setup a router which will be the responder for URL changes:
var AppRouter = Backbone.Router.extend({

  routes: {
    "*path": "load_content"
  },

  load_content: function(path){
    $('#content').load('/' + path);
  }

});
var appRouter = new AppRouter;

// Then initialize Backbone's history
Backbone.history.start({pushState: true});

Excerpt from the documentation:

To indicate that you'd like to use HTML5 pushState support in your application, use Backbone.history.start({pushState: true}). If you'd like to use pushState, but have browsers that don't support it natively use full page refreshes instead, you can add {hashChange: false} to the options.

And now every time Backbone.history.navigate is called, the AppRouter will perform an AJAX load of the path into the #content div.

To handle all links with AJAX you could use the following:

$("a").on('click', function(event){
    event.preventDefault();
    Backbone.history.navigate( event.currentTarget.pathname, {trigger: true} )
});

Take note of the {trigger: true} which causes the handler in the router to be called (otherwise only from url changes).

Cross-browser jquery ajax history with window.history.pushState and fa...

jquery ajax browser-history
Rectangle 27 4

autocomplete="off"
<input type="text" name="email" value="" autocomplete="off" />

jquery - Javascript: Prevent browser to display input history for a fi...

javascript jquery
Rectangle 27 4

autocomplete="off"
<input type="text" name="email" value="" autocomplete="off" />

jquery - Javascript: Prevent browser to display input history for a fi...

javascript jquery
Rectangle 27 3

Perhaps try this jQuery History plugin: http://www.balupton.com/sandbox/jquery-history/demo/ It provides cross browser support, binding to hashes, overloading hashes, all the rest.

There is also a Ajax extension for it, allowing it to easily upgrade your webpage into a proper Ajax application: http://www.balupton.com/sandbox/jquery-ajaxy/demo/

Overall it is well documented, supported and feature rich. It's also won a bounty question here How to show Ajax requests in URL?

jquery - The best Ajax History and Bookmark plugin currently available...

jquery ajax hashchange browser-state
Rectangle 27 1

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.

javascript - What's the best library to do a URL hash/history in JQuer...

javascript jquery ajax fragment-identifier hashchange
Rectangle 27 1

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.

javascript - What's the best library to do a URL hash/history in JQuer...

javascript jquery ajax fragment-identifier hashchange
Rectangle 27 1

You need to change the URL (hash navigation as mentioned by @marcojohannesen) when the user clicks the tab - simply assigning the cookie isn't going to help you. When the browser goes back - no ready events are fired.

Jquery history cookie for tab slider? - Stack Overflow

jquery cookies tabs history slide
Rectangle 27 1

I wrestled with this recently as well. After thinking about it, I realized I could rewrite my JQM application to use Pop Up "windows" for those pages that I didn't want in my history. This ended up being an easier and cleaner fix than mucking around with browser history.

Now users can intuitively use the browser back button, and I don't have to code application back buttons.

The only thing you have to ensure is that the popups don't themselves make it into the browser history, so make sure to set the "history" option to false like so:

$('#some_popup').popup( { history: false } );

javascript - How to modify jQuery mobile history Back Button behavior ...

javascript django jquery-mobile browser-history
Rectangle 27 0

No, it's not at simple as that. You can use the history collection to go back or forward, but you can't get the URLs in the history.

The only information that you can obtain about where the user comes from is the HTTP_REFERER string in the request header, but you have to use server side code to get that.

You can also get the Referer header from document.referrer in JS. (Yes, despite the inconsistent spelling.)

jquery - Test browser history before going back via javascript? - Stac...

javascript jquery string url browser-history
Rectangle 27 0

You can keep track of all states (links) in an Array and on popstate (or statechange) compare the new location to the old one in the array so you will know which way the user went in history (back or fwd).

Or you can pass along in the state obj (the first param to pushState) a time stamp and compare that to the old

(function(){
    /*adding some init vars*/
    var the = this, arr = [], currPage;
    var History = window.History;
    if ( !History.enabled ) {
        return false;
    }
    /* Store the initial content*/
    History.replaceState({
      content: $('#main').html()
    }, document.title, document.location.href);
    /* add to arr*/
    arr[arr.length] = document.location.href;
    /*keep track of where we arein arr*/
    currPage = arr.length -1;
    /* Bind to StateChange Event */
    History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
            var position, button;
            var State = History.getState(); // Note: We are using History.getState() instead of event.state
            //console.log(State);
            //History.log(State.data, State.title, State.url);
            console.log(history.length);
            position = arr.indexOf(document.location.href);
            button = position > currPage ? "fwd" : "back";
            currPage = position;
            console.log("You pressed The "+ button + " Button");
        });         
        /* triggers */
        $(document).on('click','a',function(e){
            e.preventDefault();
            var href = $(this).attr('href');
            var title = $(this).text();
            if(href == '#')
                href = title;
            $.get('portfolio.html',function(data, response){
                var html = $(data).find('#main-content').html();
                //console.log(html);


                $('#ajax-load').html(html);
                History.pushState({ content: html}, title, href);
                /* add to arr */
                arr[arr.length] = href;
                /* keep track */
                currPage = arr.length -1;
                $('#ajax-load').css({ position:'absolute', 
                                      right: -$(window).width(), 
                                      top: the.header.height(), 
                                      width: $(window).width(),
                                      zIndex:999
                }).animate({ right: 0 },300,function(){
                    console.log($('#main-content').length);
                    console.log($('#ajax-load').length);
                    $('#main-content').html(html);
                    $('#ajax-load').html('');
                });

            });

        });

}())

This option has a problem that it will get confused if the same link will be in the history more than once

(function(){
    /*adding some init vars*/
    var the = this, currPageTime;
    var History = window.History;
    if ( !History.enabled ) {
        return false;
    }
    /* Store the initial content*/
    /* remember the current time */
    currPageTime = new Date().getTime();
    History.replaceState({
      content: $('#main').html(),
      time : currPageTime
    }, document.title, document.location.href);
    /* Bind to StateChange Event */
    History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
            var pageTime, button;
            var State = History.getState(); // Note: We are using History.getState() instead of event.state
            //console.log(State);
            //History.log(State.data, State.title, State.url);
            console.log(history.length);
            /*NOTE: I never used getState so i dont know if State.time will exist, if not change it to whatever  holds the time we passed earlier */
            pageTime = State.time;
            button = pageTime > currPageTime ? "fwd" : "back";
            currPageTime =  pageTime;
            console.log("You pressed The "+ button + " Button");
        });         
        /* triggers */
        $(document).on('click','a',function(e){
            e.preventDefault();
            var href = $(this).attr('href');
            var title = $(this).text();
            if(href == '#')
                href = title;
            $.get('portfolio.html',function(data, response){
                var html = $(data).find('#main-content').html();
                //console.log(html);


                $('#ajax-load').html(html);
                /* keep track of time */
                currPageTime = new Date().getTime();
                History.pushState({ content: html, time: currPageTime}, title, href);
                $('#ajax-load').css({ position:'absolute', 
                                      right: -$(window).width(), 
                                      top: the.header.height(), 
                                      width: $(window).width(),
                                      zIndex:999
                }).animate({ right: 0 },300,function(){
                    console.log($('#main-content').length);
                    console.log($('#ajax-load').length);
                    $('#main-content').html(html);
                    $('#ajax-load').html('');
                });

            });

        });

}())

PS: I haven't tested if it works, if it doesn't work please make a fiddle and I'l try to fix it

jquery - History API html5, how to know when user clicked in next/back...

jquery html5 api history history.js
Rectangle 27 0

You wouldn't need to specifically see whether the next or back button is triggered. 'statechange' is the event that will be triggered when next or back button is pressed. So based on the url change you can manipulate your html content.

Also, statechange is triggered on different occasions as well in different browsers. Chrome for example loads the statechange event as soon as any page loads, even on refresh whereas this is not the case for firefox.

I do want to know because i want to treat the response differntly in those cases... ;)

jquery - History API html5, how to know when user clicked in next/back...

jquery html5 api history history.js
Rectangle 27 0

You don't want the page to save the #anchor link when clicked on the same page correct?

Use a listener, and prevent default link action.

$('a').on('click', function(event) {
    event.preventDefault();
    event.stopPropagation();
});

This will save you having multiples of the same page in history, but you'll still have the #anchor tag in the URL if navigated from another page.

Edit: Actual answer was provided by myself in comments: "You want to rewrite the URL? Your question was more towards anchor tags. If you want to change the url use: window.history.replaceState(). https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history"

I want anchor to be removed from the link(location.hash) without leaving a step in history. Is it possible?

You want to rewrite the URL? Your question was more towards anchor tags. If you want to change the url use: window.history.replaceState(). developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/

javascript - make jQuery scrollTop Not to leave browser history - Stac...

javascript jquery html scrolltop