Skip to content

Commit

Permalink
remove any usage of innerHTML (ampproject#6666)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Sep 13, 2023
1 parent 21274da commit 3153206
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/static/samples/files/amp_url_converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,26 @@ class AmpUrlConverter {
.catch(this.showError.bind(this));
}

clearResultView() {
while (this.resultView.firstChild) {
this.resultView.removeChild(this.resultView.firstChild);
}
}

showError() {
this.clearResultView();
this.resultView.className = 'error';
this.resultView.innerHTML = 'invalid URL';
this.resultView.textContent = 'invalid URL';
}

showResult(cacheUrl) {
const result =
'<a href="' + cacheUrl + '" target="_blank">' + cacheUrl + '</a>';
this.clearResultView();
const result = window.document.createElement('a');
result.setAttribute('href', cacheUrl);
result.setAttribute('target', '_blank');
result.textContent = cacheUrl;
this.resultView.className = '';
this.resultView.innerHTML = result;
this.resultView.appendChild(result);
}

onChange() {
Expand Down

0 comments on commit 3153206

Please sign in to comment.