Skip to content

A platform for community discussion. Free, open, simple.

extract inline `onpopstate` handler on 404 page (#6613)

Kyle Zhao5f754b43f1ec
diff --git a/app/assets/javascripts/onpopstate-handler.js.no-module.es6 b/app/assets/javascripts/onpopstate-handler.js.no-module.es6
new file mode 100644
index 00000000000..014ec61bf27
--- /dev/null
+++ b/app/assets/javascripts/onpopstate-handler.js.no-module.es6
@@ -0,0 +1,6 @@
+window.onpopstate = function(event) {
+ // check if Discourse object exists if not take care of back navigation
+ if (event.state && !window.hasOwnProperty("Discourse")) {
+ window.location = document.location;
+ }
+};
diff --git a/app/views/exceptions/not_found.html.erb b/app/views/exceptions/not_found.html.erb
index 4f08ba275ab..e787e78dcd2 100644
--- a/app/views/exceptions/not_found.html.erb
+++ b/app/views/exceptions/not_found.html.erb
@@ -38,11 +38,5 @@
</div>
</div>
- <script language="Javascript">
- window.onpopstate = function(event) {
- if (event.state && !window.hasOwnProperty("Discourse")) { //check if Discourse object exists if not take care of back navigation
- window.location = document.location;
- }
- };
- </script>
+ <%= preload_script('onpopstate-handler') %>
<%- end %>
diff --git a/config/application.rb b/config/application.rb
index fb61d718736..5a6899084ca 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -128,6 +128,7 @@ module Discourse
activate-account.js
auto-redirect.js
wizard-start.js
+ onpopstate-handler.js
}
# Precompile all available locales