You can create a URL object from a string using new URL(text) and get the hostname of that Object. Only thing that remains is choosing how you will extract the url from the html.
Using regex
var html = '<div class="tv-focusable" id="tv_web_answer_source" tabindex="-1" data-url="https://apple.stackexchange.com/questions/323174/does-the-iphone-8-have-any-sort-of-water-resistance-or-waterproof-manufacturing" onclick="onUrlClick(this)">';
console.log(new URL(html.match(/data-url="([^"]*)"/)[1]).hostname);
Using html
var html = '<div class="tv-focusable" id="tv_web_answer_source" tabindex="-1" data-url="https://apple.stackexchange.com/questions/323174/does-the-iphone-8-have-any-sort-of-water-resistance-or-waterproof-manufacturing" onclick="onUrlClick(this)">';
var element = document.createElement("div");
element.innerHTML = html;
var elementWithData = element.querySelector("[data-url]");
if (elementWithData) {
console.log(new URL(elementWithData.getAttribute("data-url")).hostname);
}
I would personally go with the html solution, since if (for unknown reasons) the url contains this text \", then the regex will fail (though you could just add that constraint).
Also, if you want ES5 compatibility you should use getAttribute over dataset. But this will only matter when using older versions of IE (up to 11)