Login   Register  
Icontem

File: example.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of martin barker  >  JavaScript History PushState Generator  >  example.js  >  Download  
File: example.js
Role: Example script
Content type: text/plain
Description: Example use of object
Class: JavaScript History PushState Generator
Build the URLs to add to history using pushState
Author: By
Last change: Corrected a mistake in comments
Date: 2013-10-24 05:12
Size: 1,400 bytes
 

Contents

Class file image Download
#
# E.G on website http://www.test.com/page.php&load=welcome
# push states would require you to build the url with any GET 
# params you require what happens if the params list is huge.
#

// _GET contains any GET Params used by the page
console.log(_GET);
// will result in Object {load: "welcome"}

//if you would like to append any other GET Params just add them
_GET['title'] = "Hello";
_GET.content = "World";
console.log(_GET);
// will result in Object {load: "welcome", title:"Hello", content:"World"}

//to then push the push state without changing 
//the page in the url
pushStateGen.push();
// or if you would view the generated address
pushStateGen.getPushURL();

// if you would like to change the page in the url 
// so for our example above page.php

pushStateGen.push("/page2.php");
// or if you would view the generated address
pushStateGen.getPushURL("/page2.php");

//and these work with all manner of urls that would work on a href
// more Examples below

# say we're on path http://www.test.com/test/page.php&load=welcome
pushStateGen.push("/page.php"); 
# this would return you to the top url

pushStateGen.push("http://www.test.com/test/page.php");
# this would push to the url entered however this will not work cross domain, port or protcol (https/http)

pushStateGen.push("../page.php"); 
# this would return you to the top url