{"id":982,"date":"2020-10-05T17:20:47","date_gmt":"2020-10-05T11:50:47","guid":{"rendered":"https:\/\/myfreeonlinetools.com\/blog\/?p=982"},"modified":"2020-10-27T22:37:41","modified_gmt":"2020-10-27T17:07:41","slug":"get-previous-url-or-browser-visited-page-url-by-javascript","status":"publish","type":"post","link":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/","title":{"rendered":"Get Previous URL or Browsered Visited Page URL by JavaScript"},"content":{"rendered":"<p>How to get the previous URL by using javascript.\u00a0 For the below code, I store the previous pages URL into a variable and console them. I store the history pages URL into the local storage variable.<\/p>\n<p>&nbsp;<\/p>\n<pre>&lt;script type=\"text\/javascript\"&gt;\r\n\r\nvar getBrowswerHistory = history.length; \r\nvar getLastLocation = []; \r\nvar getLocationPath = location.href; \r\ngetLastLocation.push(getLocationPath);\r\nvar broswerHistoryArray = 'broswerHistoryArray' + getBrowswerHistory ; \r\nlocalStorage.setItem(broswerHistoryArray, getLastLocation);\r\nvar first = getBrowswerHistory ; \r\nvar second = getBrowswerHistory - 1; \r\nvar thrid = getBrowswerHistory - 2;\r\nvar getBrowserHistoryFirst = 'broswerHistoryArray'+first; \r\nvar getBrowserHistorySecond = 'broswerHistoryArray'+second; \r\nvar getBrowserHistoryThird = 'broswerHistoryArray'+thrid;\r\n\r\nconsole.log(getBrowserHistoryFirst);\r\nconsole.log(getBrowserHistorySecond);\r\nconsole.log(getBrowserHistoryThird);\r\n\r\nvar getLastTwoOneUrl = localStorage.getItem(getBrowserHistoryFirst);\r\nvar getLastTwoTwoUrl = localStorage.getItem(getBrowserHistorySecond);\r\nvar getLastTwoThreeUrl = localStorage.getItem(getBrowserHistoryThird);\r\n\r\ngetLastTwoOneUrl = getLastTwoOneUrl + '<-';\r\ngetLastTwoTwoUrl = getLastTwoTwoUrl + '<-';\r\n\r\nconsole.log(getLastTwoOneUrl);\r\nconsole.log(getLastTwoTwoUrl);\r\nconsole.log(getLastTwoThreeUrl);\r\n\r\nvar browserHistoryArray = [getLastTwoOneUrl,getLastTwoTwoUrl,getLastTwoThreeUrl]; \r\n\r\nlocalStorage.setItem('arrayBrowswerLastThree', browserHistoryArray);\r\n\r\n&lt;\/script&gt;<\/pre>\n<p>Answer of Stackoverflow Answer<\/p>\n<p>Q. 1\u00a0<a class=\"question-hyperlink\" href=\"https:\/\/stackoverflow.com\/questions\/3528324\/how-to-get-the-previous-url-in-javascript\">How to get the previous URL in JavaScript?<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to get the previous URL by using javascript.\u00a0 For the below code, I store the previous pages URL into a variable and console them. I store the history pages [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1002,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[27,28],"tags":[],"class_list":["post-982","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-solution","category-jquery-code"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Get Previous URL or Browsered Visited Page URL by JavaScript - MyFreeOnlineTools<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Previous URL or Browsered Visited Page URL by JavaScript - MyFreeOnlineTools\" \/>\n<meta property=\"og:description\" content=\"How to get the previous URL by using javascript.\u00a0 For the below code, I store the previous pages URL into a variable and console them. I store the history pages [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"MyFreeOnlineTools\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/LearnSchoolOnline\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-05T11:50:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-27T17:07:41+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"225\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"myfreeonlinetools\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"myfreeonlinetools\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/\"},\"author\":{\"name\":\"myfreeonlinetools\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c\"},\"headline\":\"Get Previous URL or Browsered Visited Page URL by JavaScript\",\"datePublished\":\"2020-10-05T11:50:47+00:00\",\"dateModified\":\"2020-10-27T17:07:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/\"},\"wordCount\":60,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg\",\"articleSection\":[\"Code - Solution\",\"jQuery Code\"],\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/\",\"name\":\"Get Previous URL or Browsered Visited Page URL by JavaScript - MyFreeOnlineTools\",\"isPartOf\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg\",\"datePublished\":\"2020-10-05T11:50:47+00:00\",\"dateModified\":\"2020-10-27T17:07:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#primaryimage\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg\",\"contentUrl\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg\",\"width\":400,\"height\":225,\"caption\":\"Get Previous URL or Browser Visited Page URL by JavaScript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/myfreeonlinetools.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Previous URL or Browsered Visited Page URL by JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#website\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/\",\"name\":\"MyFreeOnlineTools\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/myfreeonlinetools.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\",\"name\":\"MyFreeOnlineTools\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png\",\"contentUrl\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png\",\"width\":387,\"height\":79,\"caption\":\"MyFreeOnlineTools\"},\"image\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c\",\"name\":\"myfreeonlinetools\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g\",\"caption\":\"myfreeonlinetools\"},\"description\":\"Live in Delhi, Working in Gurgaon as Web Designer and Graphic Designer. Developed and Design myfreeonlinetools for online free tools. Also having youtube channel Name with LearnSchoolOnline. Traveling, watching movies, coding are the hobbies.\",\"sameAs\":[\"https:\/\/myfreeonlinetools.com\/\",\"https:\/\/www.facebook.com\/LearnSchoolOnline\/\",\"https:\/\/www.youtube.com\/learnschoolonline\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Previous URL or Browsered Visited Page URL by JavaScript - MyFreeOnlineTools","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Get Previous URL or Browsered Visited Page URL by JavaScript - MyFreeOnlineTools","og_description":"How to get the previous URL by using javascript.\u00a0 For the below code, I store the previous pages URL into a variable and console them. I store the history pages [&hellip;]","og_url":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/","og_site_name":"MyFreeOnlineTools","article_author":"https:\/\/www.facebook.com\/LearnSchoolOnline\/","article_published_time":"2020-10-05T11:50:47+00:00","article_modified_time":"2020-10-27T17:07:41+00:00","og_image":[{"width":400,"height":225,"url":"http:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg","type":"image\/jpeg"}],"author":"myfreeonlinetools","twitter_card":"summary_large_image","twitter_misc":{"Written by":"myfreeonlinetools","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#article","isPartOf":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/"},"author":{"name":"myfreeonlinetools","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c"},"headline":"Get Previous URL or Browsered Visited Page URL by JavaScript","datePublished":"2020-10-05T11:50:47+00:00","dateModified":"2020-10-27T17:07:41+00:00","mainEntityOfPage":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/"},"wordCount":60,"commentCount":0,"publisher":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization"},"image":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg","articleSection":["Code - Solution","jQuery Code"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/","url":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/","name":"Get Previous URL or Browsered Visited Page URL by JavaScript - MyFreeOnlineTools","isPartOf":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#primaryimage"},"image":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg","datePublished":"2020-10-05T11:50:47+00:00","dateModified":"2020-10-27T17:07:41+00:00","breadcrumb":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#primaryimage","url":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg","contentUrl":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2020\/10\/Get-Previous-URL-or-Browser-Visited-Page-URL-by-JavaScript.jpg","width":400,"height":225,"caption":"Get Previous URL or Browser Visited Page URL by JavaScript"},{"@type":"BreadcrumbList","@id":"https:\/\/myfreeonlinetools.com\/blog\/get-previous-url-or-browser-visited-page-url-by-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/myfreeonlinetools.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Get Previous URL or Browsered Visited Page URL by JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/myfreeonlinetools.com\/blog\/#website","url":"https:\/\/myfreeonlinetools.com\/blog\/","name":"MyFreeOnlineTools","description":"","publisher":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/myfreeonlinetools.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization","name":"MyFreeOnlineTools","url":"https:\/\/myfreeonlinetools.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png","contentUrl":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png","width":387,"height":79,"caption":"MyFreeOnlineTools"},"image":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c","name":"myfreeonlinetools","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g","caption":"myfreeonlinetools"},"description":"Live in Delhi, Working in Gurgaon as Web Designer and Graphic Designer. Developed and Design myfreeonlinetools for online free tools. Also having youtube channel Name with LearnSchoolOnline. Traveling, watching movies, coding are the hobbies.","sameAs":["https:\/\/myfreeonlinetools.com\/","https:\/\/www.facebook.com\/LearnSchoolOnline\/","https:\/\/www.youtube.com\/learnschoolonline"]}]}},"_links":{"self":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/comments?post=982"}],"version-history":[{"count":0,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/982\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/media\/1002"}],"wp:attachment":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/media?parent=982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/categories?post=982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/tags?post=982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}