{"id":283,"date":"2021-02-23T02:18:00","date_gmt":"2021-02-23T02:18:00","guid":{"rendered":"https:\/\/wshop.fi\/eng\/?p=283"},"modified":"2021-03-23T02:20:37","modified_gmt":"2021-03-23T02:20:37","slug":"javascript-window-location-object-methods","status":"publish","type":"post","link":"https:\/\/wshop.fi\/eng\/javascript-window-location-object-methods\/","title":{"rendered":"Javascript Window Location Object Methods"},"content":{"rendered":"\n<p>Two of the three javascript window location object methods seem to do the same thing. &nbsp;They&nbsp;<strong>do not<\/strong>. The window&nbsp;<strong>location methods<\/strong>&nbsp;are&nbsp;<strong>assign(), reload(),<\/strong>&nbsp;and&nbsp;<strong>replace()<\/strong>. The reload() method does what you think. Both assign() and replace() appear to simply open a new page.<\/p>\n\n\n\n<p>So\u2026Uhhh\u2026.. What\u2019s the difference between javascript location.assign() and location.replace()?<\/p>\n\n\n\n<p>It has to do with your browsers history.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Difference between assign() and replace()<\/h2>\n\n\n\n<p>The \u201curl\u201d is whatever url you pass as an object for the&nbsp;javascript window location object method.<\/p>\n\n\n\n<p><code>window.location.assign(\"url\")<\/code>&nbsp;causes a new document to load, while adding the current to the history.<\/p>\n\n\n\n<p><code>window.location.replace(\"url\")<\/code>&nbsp;will replace the current document. It&nbsp;<strong><em>replaces the history<\/em>&nbsp;in the browser<\/strong>&nbsp;so you can\u2019t go back.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Javascript Window Location Object Methods<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Method<\/th><th>Description<\/th><th>More Info<\/th><\/tr><tr><td>assign()<\/td><td>Loads a new document<\/td><td>Preserves History<\/td><\/tr><tr><td>reload()<\/td><td>Reloads the current document<\/td><td><\/td><\/tr><tr><td>replace()<\/td><td>Replaces the current document with a new one (Loads a document)<\/td><td>Replaces History<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Two of the three javascript window location object methods seem to do the same thing. &nbsp;They&nbsp;do not. The window&nbsp;location methods&nbsp;are&nbsp;assign(), reload(),&nbsp;and&nbsp;replace(). The reload() method does what you think. Both assign() and replace() appear to simply open a new page. So\u2026Uhhh\u2026.. What\u2019s the difference between javascript location.assign() and location.replace()? It has to do with your browsers [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":286,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":{"0":"post-283","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-coding"},"_links":{"self":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":1,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":284,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/posts\/283\/revisions\/284"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/media\/286"}],"wp:attachment":[{"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wshop.fi\/eng\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}