Skip to content

Instantly share code, notes, and snippets.

@RatulHasan
Created October 18, 2018 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RatulHasan/51dc561177f5fc16775aa41c8d8622a0 to your computer and use it in GitHub Desktop.
Save RatulHasan/51dc561177f5fc16775aa41c8d8622a0 to your computer and use it in GitHub Desktop.
try to copy url
<script>
function copyw(e) {
e.preventDefault();
var dummy = document.createElement('input'),
text = window.location.href;
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand('copy');
document.body.removeChild(dummy);
window.location.href = "https://www.google.com/search?ei=whbIW_f1NcHwvATPnJ7gBA&q=paste+a+text+from+clipboard+javascript&oq=paste+a+text+from+clipboard+javascript&gs_l=psy-ab.3...5207947.5223187.0.5224030.27.21.6.0.0.0.171.2217.1j17.18.0....0...1c.1j4.64.psy-ab..3.5.588...35i39k1j0i7i30k1j0i5i30k1j0i7i5i30k1j0i8i30k1j0i8i7i30k1.0.Xw8_6D7Ph6w";
}
function copy(){
history.replaceState('data to be passed', 'Title of the page', "Hello!");
}
</script>
<button type="button" onclick="copy()">Copy</button>
<input type="text" id="paste" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment