Found a way to do this without javascript, currently that way is unreliable. I will update this function when the new way is reliable.