/    Sign up×
Community /Pin to ProfileBookmark

Copy script needs help

My copy code doesnt seem to work (IE Only). i want it to copy <a href=URL><img src=rgfd></a>.

Preview:
[url]http://alientest1.proboards56.com/index.cgi[/url]

my code:

<TEXTAREA ID=”innerText” display=”none” height=”1px” width=”1px”></TEXTAREA>

<script>

var border = “<table class=bordercolor cellspacing=0 width=100><tr><td>”
var table = “<table class=windowbg width=100% cellpadding=4 cellspacing=0><tr><td>”;
var marquee = “<marquee width=800>”;
var content = “FFFFF FFFFFFFFFF FF”;
var marqueeend = “</marquee>”;
var tableend = “</td></tr></table></td></tr></table>”;
var td = “</td><td>”;
var tr = “</td></tr><tr><td>”;
var code = “<a href=javascript:copy();>Copy our affiliation code!</a>”;

document.write(border+table+marquee+content+marqueeend+td+tr+code+tableend);

function copy()
{
holdtext.innerText = text.innerText;
Copied = copiedtext.createTextRange();
Copied.execCommand(“Copy”);
}

</script>

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@torunforeverSep 01.2005 — g0alieb0y, to recap your question, you want to know how to copy to the clipboard in IE.

Your code makes references to non-existent variables/objects, so I get the feeling you were piecing together your script from other sources, or you're not showing all your code.

The following should work:

function copy() {

if (!document.all) return; // IE only

r = document.getElementById('holdtext').createTextRange();

r.select();

r.execCommand('copy');

}

Another way in IE.

http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/clipboarddata.asp

Specifically look at the line

bResult = window.clipboardData.setData("Text",oSource.innerText);

The following page has an example of IE and Mozilla/Netscape code.

http://www.krikkit.net/howto_javascript_copy_clipboard.html

You can google around for nsIClipboard if you want more examples for the Moz code.

In Mozilla, it is considered a security risk to just allow clipboard access, so you'll run into a few obstacles.

The link above mentions that the user needs signed.applets.codebase_principal_support to be set to true in about:config

I don't think that's true, and keep in mind it's dangerous to keep that setting set to true.

But for the purpose of testing the clipboard code, I set signed.applets.codebase_principal_support in Firefox 1.0.6 to true and false, and regardless I was prompted with the same Firefox dialog both times that warned of "requesting enhanced abilities that are UNSAFE". When I clicked Allow, then the clipboard code worked. It can remember on a per-domain basis whether you want to allow permission all the time.
Copy linkTweet thisAlerts:
@g0alieb0yauthorSep 01.2005 — thanks but those two scripts are too big, even with out the coments.
Copy linkTweet thisAlerts:
@g0alieb0yauthorSep 01.2005 — Here is my new code:

<SPAN ID="copytext" STYLE="height:1;width:1;background-color:pink">

fgfyodzss<br><br>

</SPAN>

<TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA>

<BUTTON onClick="copy();">Copy to Clipboard</BUTTON>

<script>

var border = "<table class=bordercolor cellspacing=0 width=100><tr><td>"

var table = "<table class=windowbg width=100% cellpadding=4 cellspacing=0><tr><td>";

var marquee = "<marquee width=800>";

var content = "FFFFF FFFFFFFFFF FF";

var marqueeend = "</marquee>";

var tableend = "</td></tr></table></td></tr></table>";

var td = "</td><td>";

var tr = "</td></tr><tr><td>";

var code = "<center><a onClick=copy();>Copy our affiliation code!</a></center>";

document.write(border+table+marquee+content+marqueeend+td+tr+code+tableend);

function copy() {

if (!document.all) return; // IE only

r = document.getElementById('holdtext').createTextRange();

r.select();

r.execCommand('copy');

}

</script>

but that still doesnt copy any of the tags. (it wont copy the two <br>'s i have in it.)
Copy linkTweet thisAlerts:
@g0alieb0yauthorSep 03.2005 — bump, please help
Copy linkTweet thisAlerts:
@g0alieb0yauthorSep 04.2005 — please help.
Copy linkTweet thisAlerts:
@volkerweberSep 04.2005 — [CODE]
r = document.getElementById('holdtext').createTextRange();
r.select();
r.execCommand('copy');
[/CODE]


your are trying to copy the content of the element with id 'holdtext'.

this is your (empty) textarea!
Copy linkTweet thisAlerts:
@g0alieb0yauthorSep 04.2005 — so it copys the content in holdtext? because it was copying the content in copytext.
×

Success!

Help @g0alieb0y spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...