Dynamically changing "Canonical" link in the same page with different variables

Would this method from @Heather_Mann offer a solution?