Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working for script tags #14

Closed
IonutLaceanu opened this issue Jan 27, 2016 · 10 comments
Closed

not working for script tags #14

IonutLaceanu opened this issue Jan 27, 2016 · 10 comments

Comments

@IonutLaceanu
Copy link

I want a copy button for a text which basically is a script tag.
Something like:

<script type="text/javascript">
  var a = 2 + 3;
</script>

However, it doesn't work, becuase you are using innerHTML, which basically inserts the script inside the page.

@nkbt
Copy link
Contributor

nkbt commented Jan 27, 2016

Is it fixed if innerHTML is changed to innerText? Most likely it should be working...

@nkbt
Copy link
Contributor

nkbt commented Jan 27, 2016

http://codepen.io/nkbt/pen/eJrdWG?editors=0010

@IonutLaceanu, that works just well for me with your example. Maybe you are doing something else oddly?

Click first button to copy script content to state, then second button to copy it to clipboard

@IonutLaceanu
Copy link
Author

@nkbt, it works because you are copying the content of the script tag.
In my case, I want to copy the entire script tag.
in your code pen, enter this:
<script type="text/javascript" ref="script">var a = 2 + 3;</script>
in the input field,
then, make sure that you have something else in your clipboard (copy some random stuff)
then do copy to clipboard from button.

You'll see that it doesn't work.

I'll try with inner text and see if it works.

@IonutLaceanu
Copy link
Author

@nkbt, I can confirm that it works like a charm with innerText

@nkbt
Copy link
Contributor

nkbt commented Jan 27, 2016

Well, yeah, if you paste script as innerHTML that should not really work. Moreover that is quite dangerous =). I would not recommend doing that. But changing to innerText seems like a really good idea (for safety reasons too). Keen to PR?

IonutLaceanu added a commit to IonutLaceanu/copy-to-clipboard that referenced this issue Jan 27, 2016
IonutLaceanu added a commit to IonutLaceanu/copy-to-clipboard that referenced this issue Jan 28, 2016
Fix sudodoki#14: replace innerHTML with innerText
@nkbt
Copy link
Contributor

nkbt commented Feb 9, 2016

Might be the issue with nkbt/react-copy-to-clipboard#15 too

@sudodoki
Copy link
Owner

sudodoki commented Feb 9, 2016

@nkbt will try to find time this week

@nkbt
Copy link
Contributor

nkbt commented Feb 9, 2016

Thanks, @sudodoki.

I think you can also try to create a textarea instead of div.

@sudodoki sudodoki mentioned this issue Feb 9, 2016
@sudodoki
Copy link
Owner

sudodoki commented Feb 9, 2016

Should be fixed by #19 let me know, if latest master works for you and I'll publish version. @nkbt @IonutLaceanu.

@sudodoki
Copy link
Owner

Considering this closed now. Please, let me know if something still doesn't work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants