Created
October 23, 2013 14:28
-
-
Save klittle32/7119885 to your computer and use it in GitHub Desktop.
Detect iNet page type via javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Script to detect page type on Epicor iNet sites 2.5.3 and higher | |
| //Version 1.0, 8/29/2013 | |
| // For dynamic urls, use parameters and values in url string | |
| // Create getQueryVariable function to access values in query string | |
| function getQueryVariable(variable) | |
| { | |
| var query = window.location.search.substring(1); | |
| var vars = query.split("&"); | |
| for (var i=0;i<vars.length;i++) { | |
| var pair = vars[i].split("="); | |
| if(pair[0] == variable){return pair[1];} | |
| } | |
| return(false); | |
| } | |
| // For static URLs, use the pathname | |
| // Get the path name | |
| var path = window.location.pathname; | |
| var pathArray = window.location.pathname.split('/'); | |
| //Instantiate the variable pageType | |
| var pageType; | |
| // Set the page type | |
| // Set the pageType variable to 'category' if a category page, but not if /departments is site's homepage | |
| if ( | |
| ( pathArray[1] == 'departments' | |
| && (typeof pathArray[2] != 'undefined') ) | |
| || (getQueryVariable('mode') == 'browsecategory' ) | |
| ) { | |
| var pageType = 'category'; | |
| }; | |
| // set the pageType variable to 'product' if a product detail page | |
| if (pathArray[1] == 'products' || getQueryVariable('mode') == 'showproductdetail') { | |
| var pageType = 'product'; | |
| }; | |
| // set the pageType variable to 'viewCart' if a viewcart page | |
| if (getQueryVariable('mode') == 'viewcart' || ( getQueryVariable('mode') =='checkout' ) ) { | |
| var pageType = 'viewCart'; | |
| }; | |
| // set the pageType to enterShippingAddress if at first step of checkout | |
| if (getQueryVariable('mode') == 'scheckout') { | |
| var pageType = 'enterShippingAddress'; | |
| }; | |
| // set the pageType to selectShippingMethod if at fedex/ups, etc page | |
| if (getQueryVariable('mode') == 'checkout' && getQueryVariable('action') == 'shipping') { | |
| var pageType = 'selectShippingMethod'; | |
| }; | |
| // set the pageType to 'reviewOrder' if at review&payment page | |
| if (getQueryVariable('mode') == 'checkout' && getQueryVariable('action') == 'payment') { | |
| var pageType = 'reviewOrder'; | |
| }; | |
| // set the pageType to 'creditCard' if at Epicor Payment Exchange pay page | |
| if (pathArray[3] == 'paypage_redirect.php' ) { | |
| var pageType = 'creditCard'; | |
| }; | |
| // set the pageType to 'receipt' if sale completed | |
| if (getQueryVariable('mode') == 'receipt') { | |
| var pageType = 'receipt'; | |
| }; | |
| //default to 'other' if not set by above conditions | |
| if(typeof pageType === 'undefined'){ | |
| var pageType = 'other'; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment