The Whiz of Oz
The Whiz of Oz

Reputation: 7043

How to copy HTML tags to clipboard without changes?

I am using this SO answer to copy page content using pure JavaScript on user click. However my content contains HTML tags:

<script>http://localhost:3000/widget/174b6b69bcf352803a00</script>

When pasted from the clipboard it turns into this:

&lt;script&gt;http://localhost:3000/widget/174b6b69bcf352803a00&lt;/script&gt;

How can I revert it back?

Upvotes: 2

Views: 1426

Answers (3)

Twiknight
Twiknight

Reputation: 39

I mistook URI ecoding with HTML entities...

That was a stupid mistake...

see this question:

How to convert characters to HTML entities using plain JavaScript

Upvotes: 0

GolezTrol
GolezTrol

Reputation: 116180

Use innerText instead of innerHTML to get the plain text version without HTML tags in it.

Upvotes: 3

Apolo
Apolo

Reputation: 4050

Here is a way to parse HTML entities :

function parseHTMLEntities(htmlString) {
  var e = document.createElement("div");
  e.innerHTML = htmlString;
  return e.innerText;
}

// use like this :

var text = parseHTMLEntities("&lt;script&gt;http://localhost:3000/widget/174b6b69bcf352803a00&lt;/script&gt;");

alert(text);

Upvotes: 1

Related Questions