I want to Update rel=canonical href using Java Script

I understand.

You are missing an opening quote in your script conditional statement BTW …