如何在重定向後顯示警報?如何在javascript重定向後顯示警報?
def index
respond_to do |format|
if user_signed_in?
format.js
else
format.js {render :js => "window.location = #{code_path.to_json}"}
end
end
end
index.js.erb的
window.location = '/cabinet';
alert('hey');
你應該從'/ cabinet'頁面的'alert()'出來。重定向後,你無法做任何事情。 –
[可以在window.location加載新的URL之後調用一個函數的可能的重複嗎?](http://stackoverflow.com/questions/7493847/is-is-possible-to-call-a-function-after -window-location-has-loaded-new-url) –
也許你需要在查詢字符串或瀏覽器存儲中設置一些標誌 –