Roberto89 Roberto89 - 1 year ago 80
Javascript Question

How to disable js script on specific page?

Idea: I want to disable js script on specific page(e.g

), that is placed in
. On another page script should works. Have you any idea how to solve this problem? I thought to use loop
unless current_page?(new_post_path)
, but it's not work in js file.

Simple script to disable:

window.setTimeout(function() {
$(".alert").fadeTo(500, 0).slideUp(500, function() {
}, 10000);

Geo Geo
Answer Source

You could set two attributes in the layout:

<body data-controller="<%= controller_name %>" data-action="<%= action_name %>">


and from your js, check the value of data-controller and data-action to know whether or not you want to run the script on that action.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download