I have a requirement to copy url from address bar to clipboard using jquery when clciked on a link , but that should also work if opened in mobile iphone or android , as its a mobile site and developed using php . I really need help , please help me. I have tried zclip plugin but it is working only when its opened in desktop but not working in mobile. So I really need help to copy content to clipboard and use that data later on to paste on something else.
Asked
Active
Viewed 4,093 times
0
-
mind sharing why you have to have this feature like that? just saying, using javascript to change someones clipboard can very well be removed forever in future releases, this shouldn't be allowed in the first place – Toskan Sep 02 '14 at 06:38
-
1**Welcome to StackOverflow!** - before asking a question you should search StackOverflow for a question that matches your own (even if you don't, SO shows you possible duplicates as you enter your title!!!). Anyway - Javascript doesn't have access to the clipboard. If you searched for this topic you would find [plenty](http://stackoverflow.com/questions/22581345/jquery-click-button-copy-to-clipboard) of [posts](http://stackoverflow.com/questions/1539641/how-to-copy-text-to-the-clients-clipboard-using-jquery) on this already - voting to close. – scrowler Sep 02 '14 at 06:41
2 Answers
0
location.href
will give you the URL
following code will work for you.
$(document).ready(function(){
$('#div1').click(function(){
$("#url1").html(location.href);
});
});
click here for demo DEMO
check my new code i have done it using zclip

Domain
- 11,562
- 3
- 23
- 44
-
Hi,@Wisdmlabs thanx forthe comment but ,my requirement is to copy the url in clipboard , so that i can use it anywhere else , – RITESH NAG Sep 02 '14 at 07:15
-1
Get the URL.
var pathname = window.location.pathname;
And follow these instructions to copy:
http://ready2gosoft.com/jquery-javascript/copy-clipboard-javascript.html

Felix Frank
- 8,125
- 1
- 23
- 30

Ricard
- 17
- 3