jabber1111 jabber1111 - 1 year ago 143
CoffeeScript Question

coffeescript update url if contains string

I'm trying to change url if it contains the word 'register'. I can do this, but the page continues to loop and doesn't stop. Does anyone know how I can get the page to update to

without making the page continuously loop? Thanks

if window.location.href.indexOf("register") > -1
window.location.href = 'register'+ '?bypass_verification=true'

Answer Source

Your if condition is matching your new URL once you've redirected back with the bypass_verification parameter set. Since this still matches your condition, you are getting what appears to be a loop. You need to change your logic so that window.location.href doesn't get reassigned if it already contains bypass_verification=true.

Here is one approach that should work:

if window.location.href.indexOf("register") > -1
    window.location.href = 'register'+ '?bypass_verification=true' unless window.location.href.indexOf("?bypass_verification=true") > 0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download