I want to Update rel=canonical href using Java Script

Yes, that article indeed clearly states that they have seen canonical tags that were dynamically inserted behave exactly the same as if they were in source code. You are right (and I should have read this more thoroughly the first time you posted it).

Although three of the four pages you referred to in this topic, including the one that gave us the answer, are even older than that article I posted :wink: