Search Results

Search found 14 results on 1 pages for 'pushstate'.

Page 1/1 | 1 

  • How to get notified about changes of the history via history.pushState?

    - by Felix Kling
    So now that HTML5 introduces history.pushState to change the browsers history, websites start using this in combination with Ajax instead of changing the fragment identifier of the URL. Sadly that means that those calls cannot be detect anymore by onhashchange. My question is: Is there a reliable way (hack? ;)) to detect when a website uses history.pushState? The specification does not state anything about events that are raised (at least I couldn't find anything). I tried to create a facade and replaced window.history with my own JavaScript object, but it didn't have any effect at all. Further explanation: I'm developing a Firefox add-on that needs to detect these changes and act accordingly. I know there was a similar question a few days ago that asked whether listening to some DOM events would be efficient but I would rather not rely on that because these events can be generated for a lot of different reasons. Update: Here is a jsfiddle (use Firefox 4 or Chrome 8) that shows that onpopstate is not triggered when pushState is called (or am I doing something wrong? Feel free to improve it!). Update 2: Another (side) problem is that window.location is not updated when using pushState (but I read about this already here on SO I think).

    Read the article

  • History.js not working in Internet Explorer

    - by Wilcoholic
    I am trying to get history.js to work in Internet Explorer because I need history.pushState() to work. I have read over the instructions on GitHub (https://github.com/balupton/History.js/) and have tried implementing it, but havent had any success. Here's what I have <!DOCTYPE html> <html> <head> <!-- jQuery --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <!-- History.js --> <script defer src="http://balupton.github.com/history.js/scripts/bundled/html4+html5/jquery.history.js"></script> <script type="text/javascript"> function addHistory(){ // Prepare var History = window.History; // Note: We are using a capital H instead of a lower h // Change our States History.pushState(null, null, "?mylink.html"); } </script> </head> <body> <a href="mylink.html">My Link</a> <a href="otherlink.html">Other Link</a> <button onclick="addHistory()" type="button">Add History</button> </body> Not sure what I'm doing wrong, but it's definitely not working in IE. Any help is appreciated

    Read the article

  • Backbone.js routing without changing url

    - by louism
    I am migrating a single-page web application based on Backbone.js and jQuery to a Chrome extension. However, neither the pushState nor the hashbang-based router modes seem to play well with the environment within the extension. I've come to the conclusion that I'm better off just directly rendering views on user interactions, bypassing the window.location system altogether. However, I'm not too sure how to implement this without changing calls to Router.navigate in dozens of files. Is there a pluggable/modular way to keep the Backbone routing system but bypass any changes to the url?

    Read the article

  • How to use PJAX? (PJAX With PHP?)

    - by user1302430
    I was trying to get PJAX working with my PHP site, this is the code I am using for it: <script src="js/jquery.js"></script> <script src="js/jquery.pjax.js"></script> <script type="text/javascript"> $(function(){ // pjax $('ul a').pjax('section') }) </script> I am just using the code they used on the PJAX demo page, but replacing the container they used (#main) with the one for my site, which was the section tag. There are no errors on the console or on the page, but it doesn't work either! Before I was using $(function() { $('ul a').pjax('section') }); and $('document').ready(function(){ $('ul a').pjax('section') }); But when I don't use either of those and just use $('ul a').pjax('section') I see this error in the console: Uncaught no pjax container for section in jquery.pjax.js (line: 353) Could I get some help with this? Thanks

    Read the article

  • Backbone.js: How to utilize router.navigate to manipulate browser history?

    - by Xavier_Ex
    I am writing something like a registration process containing several steps, and I want to make it a single-page like system so after some studying Backbone.js is my choice. Every time the user completes the current step they will click on a NEXT button I create and I use the router.navigate method to update the url, as well as loading the content of the next page and doing some fancy transition with javascript. Result is, URL is updated which the page is not refreshed, giving a smooth user experience. However, when the user clicks on the back button of the browser, the URL gets updated to that of a previous step, but the content stays the same. My question is through what way I can capture such an event and currently load the content of the previous step and present that to the user? Or even better, can I rely on browser cache to load that previously loaded page? EDIT: in particular, I'm trying something like mentioned in this article.

    Read the article

  • When Googlebot sees a link, will it click it or navigate to it?

    - by FakeRainBrigand
    My site uses pushState and JSON data to display content. So, for example, this might appear on my page: <a href="/some/page">some page</a> The JavaScript then prevents the default action (following the link), and instead renders a view (using a different api, such as /getjson?some_page). $('[href]').click(function(){ history.pushState(...); handleURL(...); }); Assume my server will respond to requests at /some/page with a pre-rendered version. My questions are: will Googlebot receive the prerendered version, or allow JavaScript to instead invoke pushState, etc. if it doesn't make the direct request, will it wait for AJAX content to be loaded? does Googlebot implement pushState, so it will show the proper URL in search results?

    Read the article

  • Change URL of a saved HTML file

    - by Paul Camilleri
    I am new to HTML so this question might sound a bit lame. Anyways I have a saved webpage on my desktop that when i open it in google chrome i want it to show a specific URL instead of its current location. Any ideas how i might get this to work? I tried using the history.pushState but i have no idea why it is not working. I created a simple page for now to test it: <html> <head> <script> function setURL() { history.pushState("Test","page2", "www.test.com"); } </script> </head> <body> <button type="button" onclick="setURL()">Set Url</button> </body> </html> Any help would be greatly appreciated. Thank you

    Read the article

  • Questions about game states

    - by MrPlow
    I'm trying to make a framework for a game I've wanted to do for quite a while. The first thing that I decided to implement was a state system for game states. When my "original" idea of having a doubly linked list of game states failed I found This blog and liked the idea of a stack based game state manager. However there were a few things I found weird: Instead of RAII two class methods are used to initialize and destroy the state Every game state class is a singleton(and singletons are bad aren't they?) Every GameState object is static So I took the idea and altered a few things and got this: GameState.h class GameState { private: bool m_paused; protected: StateManager& m_manager; public: GameState(StateManager& manager) : m_manager(manager), m_paused(false){} virtual ~GameState() {} virtual void update() = 0; virtual void draw() = 0; virtual void handleEvents() = 0; void pause() { m_paused = true; } void resume() { m_paused = false; } void changeState(std::unique_ptr<GameState> state) { m_manager.changeState(std::move(state)); } }; StateManager.h class GameState; class StateManager { private: std::vector< std::unique_ptr<GameState> > m_gameStates; public: StateManager(); void changeState(std::unique_ptr<GameState> state); void StateManager::pushState(std::unique_ptr<GameState> state); void popState(); void update(); void draw(); void handleEvents(); }; StateManager.cpp StateManager::StateManager() {} void StateManager::changeState( std::unique_ptr<GameState> state ) { if(!m_gameStates.empty()) { m_gameStates.pop_back(); } m_gameStates.push_back( std::move(state) ); } void StateManager::pushState(std::unique_ptr<GameState> state) { if(!m_gameStates.empty()) { m_gameStates.back()->pause(); } m_gameStates.push_back( std::move(state) ); } void StateManager::popState() { if(!m_gameStates.empty()) m_gameStates.pop_back(); } void StateManager::update() { if(!m_gameStates.empty()) m_gameStates.back()->update(); } void StateManager::draw() { if(!m_gameStates.empty()) m_gameStates.back()->draw(); } void StateManager::handleEvents() { if(!m_gameStates.empty()) m_gameStates.back()->handleEvents(); } And it's used like this: main.cpp StateManager states; states.changeState( std::unique_ptr<GameState>(new GameStateIntro(states)) ); while(gamewindow::gameWindow.isOpen()) { states.handleEvents(); states.update(); states.draw(); } Constructors/Destructors are used to create/destroy states instead of specialized class methods, state objects are no longer static but

    Read the article

  • jQuery, ASP.NET, and Browser History

    - by Stephen Walther
    One objection that people always raise against Ajax applications concerns browser history. Because an Ajax application updates its content by performing sneaky Ajax postbacks, the browser backwards and forwards buttons don’t work as you would normally expect. In a normal, non-Ajax application, when you click the browser back button, you return to a previous state of the application. For example, if you are paging through a set of movie records, you might return to the previous page of records. In an Ajax application, on the other hand, the browser backwards and forwards buttons do not work as you would expect. If you navigate to the second page in a list of records and click the backwards button, you won’t return to the previous page. Most likely, you will end up navigating away from the application entirely (which is very unexpected and irritating). Bookmarking presents a similar problem. You cannot bookmark a particular page of records in an Ajax application because the address bar does not reflect the state of the application. The Ajax Solution There is a solution to both of these problems. To solve both of these problems, you must take matters into your own hands and take responsibility for saving and restoring your application state yourself. Furthermore, you must ensure that the address bar gets updated to reflect the state of your application. In this blog entry, I demonstrate how you can take advantage of a jQuery library named bbq that enables you to control browser history (and make your Ajax application bookmarkable) in a cross-browser compatible way. The JavaScript Libraries In this blog entry, I take advantage of the following four JavaScript files: jQuery-1.4.2.js – The jQuery library. Available from the Microsoft Ajax CDN at http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js jquery.pager.js – Used to generate pager for navigating records. Available from http://plugins.jquery.com/project/Pager microtemplates.js – John Resig’s micro-templating library. Available from http://ejohn.org/blog/javascript-micro-templating/ jquery.ba-bbq.js – The Back Button and Query (BBQ) Library. Available from http://benalman.com/projects/jquery-bbq-plugin/ All of these libraries, with the exception of the Micro-templating library, are available under the MIT open-source license. The Ajax Application Let’s start by building a simple Ajax application that enables you to page through a set of movie database records, 3 records at a time. We’ll use my favorite database named MoviesDB. This database contains a Movies table that looks like this: We’ll create a data model for this database by taking advantage of the ADO.NET Entity Framework. The data model looks like this: Finally, we’ll expose the data to the universe with the help of a WCF Data Service named MovieService.svc. The code for the data service is contained in Listing 1. Listing 1 – MovieService.svc using System.Data.Services; using System.Data.Services.Common; namespace WebApplication1 { public class MovieService : DataService<MoviesDBEntities> { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("Movies", EntitySetRights.AllRead); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; } } } The WCF Data Service in Listing 1 exposes the movies so that you can query the movie database table with URLs that looks like this: http://localhost:2474/MovieService.svc/Movies -- Returns all movies http://localhost:2474/MovieService.svc/Movies?$top=5 – Returns 5 movies The HTML page in Listing 2 enables you to page through the set of movies retrieved from the WCF Data Service. Listing 2 – Original.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Movies with History</title> <link href="Design/Pager.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Page <span id="pageNumber"></span> of <span id="pageCount"></span></h1> <div id="pager"></div> <br style="clear:both" /><br /> <div id="moviesContainer"></div> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script> <script src="App_Scripts/Microtemplates.js" type="text/javascript"></script> <script src="App_Scripts/jquery.pager.js" type="text/javascript"></script> <script type="text/javascript"> var pageSize = 3, pageIndex = 0; // Show initial page of movies showMovies(); function showMovies() { // Build OData query var query = "/MovieService.svc" // base URL + "/Movies" // top-level resource + "?$skip=" + pageIndex * pageSize // skip records + "&$top=" + pageSize // take records + " &$inlinecount=allpages"; // include total count of movies // Make call to WCF Data Service $.ajax({ dataType: "json", url: query, success: showMoviesComplete }); } function showMoviesComplete(result) { // unwrap results var movies = result["d"]["results"]; var movieCount = result["d"]["__count"] // Show movies using template var showMovie = tmpl("<li><%=Id%> - <%=Title %></li>"); var html = ""; for (var i = 0; i < movies.length; i++) { html += showMovie(movies[i]); } $("#moviesContainer").html(html); // show pager $("#pager").pager({ pagenumber: (pageIndex + 1), pagecount: Math.ceil(movieCount / pageSize), buttonClickCallback: selectPage }); // Update page number and page count $("#pageNumber").text(pageIndex + 1); $("#pageCount").text(movieCount); } function selectPage(pageNumber) { pageIndex = pageNumber - 1; showMovies(); } </script> </body> </html> The page in Listing 3 has the following three functions: showMovies() – Performs an Ajax call against the WCF Data Service to retrieve a page of movies. showMoviesComplete() – When the Ajax call completes successfully, this function displays the movies by using a template. This function also renders the pager user interface. selectPage() – When you select a particular page by clicking on a page number in the pager UI, this function updates the current page index and calls the showMovies() function. Figure 1 illustrates what the page looks like when it is opened in a browser. Figure 1 If you click the page numbers then the browser history is not updated. Clicking the browser forward and backwards buttons won’t move you back and forth in browser history. Furthermore, the address displayed in the address bar does not change when you navigate to different pages. You cannot bookmark any page except for the first page. Adding Browser History The Back Button and Query (bbq) library enables you to add support for browser history and bookmarking to a jQuery application. The bbq library supports two important methods: jQuery.bbq.pushState(object) – Adds state to browser history. jQuery.bbq.getState(key) – Gets state from browser history. The bbq library also supports one important event: hashchange – This event is raised when the part of an address after the hash # is changed. The page in Listing 3 demonstrates how to use the bbq library to add support for browser navigation and bookmarking to an Ajax page. Listing 3 – Default.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Movies with History</title> <link href="Design/Pager.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Page <span id="pageNumber"></span> of <span id="pageCount"></span></h1> <div id="pager"></div> <br style="clear:both" /><br /> <div id="moviesContainer"></div> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script> <script src="App_Scripts/jquery.ba-bbq.js" type="text/javascript"></script> <script src="App_Scripts/Microtemplates.js" type="text/javascript"></script> <script src="App_Scripts/jquery.pager.js" type="text/javascript"></script> <script type="text/javascript"> var pageSize = 3, pageIndex = 0; $(window).bind('hashchange', function (e) { pageIndex = e.getState("pageIndex") || 0; pageIndex = parseInt(pageIndex); showMovies(); }); $(window).trigger('hashchange'); function showMovies() { // Build OData query var query = "/MovieService.svc" // base URL + "/Movies" // top-level resource + "?$skip=" + pageIndex * pageSize // skip records + "&$top=" + pageSize // take records +" &$inlinecount=allpages"; // include total count of movies // Make call to WCF Data Service $.ajax({ dataType: "json", url: query, success: showMoviesComplete }); } function showMoviesComplete(result) { // unwrap results var movies = result["d"]["results"]; var movieCount = result["d"]["__count"] // Show movies using template var showMovie = tmpl("<li><%=Id%> - <%=Title %></li>"); var html = ""; for (var i = 0; i < movies.length; i++) { html += showMovie(movies[i]); } $("#moviesContainer").html(html); // show pager $("#pager").pager({ pagenumber: (pageIndex + 1), pagecount: Math.ceil(movieCount / pageSize), buttonClickCallback: selectPage }); // Update page number and page count $("#pageNumber").text(pageIndex + 1); $("#pageCount").text(movieCount); } function selectPage(pageNumber) { pageIndex = pageNumber - 1; $.bbq.pushState({ pageIndex: pageIndex }); } </script> </body> </html> Notice the first chunk of JavaScript code in Listing 3: $(window).bind('hashchange', function (e) { pageIndex = e.getState("pageIndex") || 0; pageIndex = parseInt(pageIndex); showMovies(); }); $(window).trigger('hashchange'); When the hashchange event occurs, the current pageIndex is retrieved by calling the e.getState() method. The value is returned as a string and the value is cast to an integer by calling the JavaScript parseInt() function. Next, the showMovies() method is called to display the page of movies. The $(window).trigger() method is called to raise the hashchange event so that the initial page of records will be displayed. When you click a page number, the selectPage() method is invoked. This method adds the current page index to the address by calling the following method: $.bbq.pushState({ pageIndex: pageIndex }); For example, if you click on page number 2 then page index 1 is saved to the URL. The URL looks like this: Notice that when you click on page 2 then the browser address is updated to look like: /Default.htm#pageIndex=1 If you click on page 3 then the browser address is updated to look like: /Default.htm#pageIndex=2 Because the browser address is updated when you navigate to a new page number, the browser backwards and forwards button will work to navigate you backwards and forwards through the page numbers. When you click page 2, and click the backwards button, you will navigate back to page 1. Furthermore, you can bookmark a particular page of records. For example, if you bookmark the URL /Default.htm#pageIndex=1 then you will get the second page of records whenever you open the bookmark. Summary You should not avoid building Ajax applications because of worries concerning browser history or bookmarks. By taking advantage of a JavaScript library such as the bbq library, you can make your Ajax applications behave in exactly the same way as a normal web application.

    Read the article

  • Alternative to pjax/djax and ajaxy

    - by elluca
    I was evaluating jQuery plugins to make a Drupal 7 site using AJAX everywhere. I have been using ajaxy. But it does not seem to be very actively maintained. Two possible solutions I have found are pjax and djax. What are your experiences with those plugins? What other plugins do you know that do similar functionality? Very important features are SEO friendliness (preferably using pushState so no hash is being used. Hashes are used as a fallback for not supported browsers.). And also has to be very flexible since it has to wirk with Drupal's HTML structure.

    Read the article

  • How to open email by x-gm-msgid in Gmail with Javascript

    - by Rui J
    I'm writing an extension which surfaces links to gmail messages. As the UI loads right in Gmail, I should be able to click on one of these links and have Gmail load it (without refreshing). I have "x-gm-msgid" available and theoretically, I should just be able to navigate to "https://mail.google.com/mail/u/0/#inbox/[x-gm-msgid]". I've tried using location.hash = "#inbox/[x-gm-msgid]" I've tried using history.pushState(null, null, "/mail/u/0/#inbox/[x-gm-msgid]") Neither of which works. Gmail just thwarts any attempt to change the URL (unless it is done via user interaction) Any thoughts on how to get around this restriction?

    Read the article

  • Why does my buffered GraphicsContext application have a flickering problem?

    - by Bibendum
    import wx class MainFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self, parent, title=title, size=(640,480)) self.mainPanel=DoubleBufferTest(self,-1) self.Show(True) class DoubleBufferTest(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,style=wx.FULL_REPAINT_ON_RESIZE) self.SetBackgroundColour("#FFFFFF") self.timer = wx.Timer(self) self.timer.Start(100) self.Bind(wx.EVT_TIMER, self.update, self.timer) self.Bind(wx.EVT_PAINT,self.onPaint) def onPaint(self,event): event.Skip() dc = wx.MemoryDC() dc.SelectObject(wx.EmptyBitmap(640, 480)) gc = wx.GraphicsContext.Create(dc) gc.PushState() gc.SetBrush(wx.Brush("#CFCFCF")) bgRect=gc.CreatePath() bgRect.AddRectangle(0,0,640,480) gc.FillPath(bgRect) gc.PopState() dc2=wx.PaintDC(self) dc2.Blit(0,0,640,480,dc,0,0) def update(self,event): self.Refresh() app = wx.App(False) f=MainFrame(None,"Test") app.MainLoop() I've come up with this code to draw double buffered GraphicsContext content onto a panel, but there's a constant flickering across the window. I've tried different kinds of paths, like lines and curves but it's still there and I don't know what's causing it.

    Read the article

  • how do i specify the element when loading content ajax jquery

    - by phukkie
    How can I specify an element where the content is to be retrieved from within the pageurl in the code below? $(function () { $("a[rel='sort']").click(function (e) { //e.preventDefault(); /* if uncomment the above line, html5 nonsupported browers won't change the url but will display the ajax content; if commented, html5 nonsupported browers will reload the page to the specified link. */ //get the link location that was clicked pageurl = $(this).attr('href'); //to get the ajax content and display in div with id 'content' $.ajax({ url: pageurl + '?rel=sort', success: function (data) { $('#content1').html(data); } }); //to change the browser URL to 'pageurl' if (pageurl != window.location) { window.history.pushState({ path: pageurl }, '', pageurl); } return false; }); });

    Read the article

  • Why Backbone.js isn't binding my event

    - by Saif Bechan
    I have a router like this, as main entry point: window.AppRouter = Backbone.Router.extend({ routes: { '': 'login' }, login: function(){ userLoginView = new UserLoginView(); } }); var appRouter = new AppRouter; Backbone.history.start({pushState: true}); I have a model/collection/view like this: window.User = Backbone.Model.extend({}); window.Users = Backbone.Collection.extend({ model: User }); window.UserLoginView = Backbone.View.extend({ events: { 'click #login-button': 'loginAction' }, initialize: function(){ _.bindAll(this, 'render', 'loginAction'); }, loginAction: function(){ var uid = $("#login-username").val(); var pwd = $("#login-password").val(); var user = new User({uid:uid, pwd:pwd}); } }); And body of my HTML looks like this: <form action="#" method="POST" id="login-form"> <p> <label for="login-username">username</label> <input type="text" id="login-username" autofocus /> </p> <p> <label for="login-password">password</label> <input type="password" id="login-password" /> </p> <a id="login-button" href="#">Inloggen</a> </form> Note: The HTML comes from Node.js using express.js, should I maybe wait for a document ready event somewhere? Edit: I have tried this, create the view when ready, did not solve the problem. $(function(){ userLoginView = new UserLoginView(); });

    Read the article

1