Instead of looping through all the link tags and looking for canonical, the canonical href can be retrieved using a single line:
Code:
document.querySelector('link[rel="canonical"]').href
--------------- Added [DATE]1469420994[/DATE] at [TIME]1469420994[/TIME] ---------------
If the discus code is inserted after the jQuery include, you can also use:
Code:
$('link[rel="canonical"]').attr('href')