By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,770 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

copy filenaam in javascript function

P: n/a
Hi All,

I have a rather complicated problem.
I use following function to display a hyperlink:

a="<"+"a href='";
b3="<"+"a href='http://nww.";
L="</"+'a><br>';

function h(a){document.writeln(a)}
function HN(link,tekst){target=telt();if
(wi==1)target="_top";h(b3+link+"'"+tag+target+"'"+ "onclick='n(\""+target+"\",\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)}

Now I need an additional option to store a filename like:
function HN(link,tekst, filename)

The function HN should be rearranged that when I click this hyperlink
the filename gets stored to the clipboard, so I can release it with
Ctrl-V.

For Example:
HN('nix.nothing.int/WHERE/2005','My
Hyperlink','NIX.NOTHING.TEXT.20050723.')

Where the last part: NIX.NOTHING.TEXT.20050723. is the part which needs
to be copied to the clipboard.

Anyone knows how I should change the function HN to get this done?
Or is it not possible?

Regards

Marco
The Netherlands

Jul 23 '05 #1
Share this Question
Share on Google+
18 Replies


P: n/a
ma************@zonnet.nl wrote:
The function HN should be rearranged that when I click this hyperlink
the filename gets stored to the clipboard, so I can release it with
Ctrl-V.

For Example:
HN('nix.nothing.int/WHERE/2005','My
Hyperlink','NIX.NOTHING.TEXT.20050723.')

Where the last part: NIX.NOTHING.TEXT.20050723. is the part which
needs to be copied to the clipboard.

Anyone knows how I should change the function HN to get this done?
Or is it not possible?


function HN(link, tekst, clipdata) {
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}
...
}
JW

Jul 23 '05 #2

P: n/a
Janwillem,

Thanks for the help but where exactly should I add this piece of code?
Like this?

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
{target=telt();if
(wi==1)target="_top";h(b3+link+"'"+tag+target+"'"+ "onclick='n(\""+target+"\"
,\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)}
}

Marco

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:42***********************@news.euronet.nl...
ma************@zonnet.nl wrote:
The function HN should be rearranged that when I click this hyperlink
the filename gets stored to the clipboard, so I can release it with
Ctrl-V.

For Example:
HN('nix.nothing.int/WHERE/2005','My
Hyperlink','NIX.NOTHING.TEXT.20050723.')

Where the last part: NIX.NOTHING.TEXT.20050723. is the part which
needs to be copied to the clipboard.

Anyone knows how I should change the function HN to get this done?
Or is it not possible?


function HN(link, tekst, clipdata) {
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}
...
}
JW

Jul 23 '05 #3

P: n/a
Marco Krechting wrote:
Janwillem,

Thanks for the help but where exactly should I add this piece of code?
Like this?

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
{target=telt();if
(wi==1)target="_top";h(b3+link+"'"+tag+target+"'"+ "onclick='n(\""+target+"\"
,\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)}
}


No, because this will render the function useless to other browsers then IE.
The only part that needs to be excluded from other browsers is the
window.clipboardData bit. Take the code I have shown you before and insert
the original function body below it:

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}

// Original function body
target=telt();

// I assume wi is defined somewhere?
if (wi==1) {
target="_top";
}
h(....);
}
JW

Jul 24 '05 #4

P: n/a
I tried the code listed below but it doesn't work:

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}

// Original function body
{target=telt();
if (wi==1)target="_top";

h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+"http://nww."+li
nk+"\",\""+tekst+"\")'"+">"+tekst+L);
}

What went wrong?

Regards
MArco

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:42***********************@news.euronet.nl...
Marco Krechting wrote:
Janwillem,

Thanks for the help but where exactly should I add this piece of code?
Like this?

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
{target=telt();if
(wi==1)target="_top";h(b3+link+"'"+tag+target+"'"+ "onclick='n(\""+target+"\" ,\""+"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L)}
}

No, because this will render the function useless to other browsers then

IE. The only part that needs to be excluded from other browsers is the
window.clipboardData bit. Take the code I have shown you before and insert
the original function body below it:

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}

// Original function body
target=telt();

// I assume wi is defined somewhere?
if (wi==1) {
target="_top";
}
h(....);
}
JW

Jul 24 '05 #5

P: n/a
Marco Krechting wrote:
I tried the code listed below but it doesn't work:

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}

// Original function body
{target=telt();
if (wi==1)target="_top";

h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+"http://nww."+li
nk+"\",\""+tekst+"\")'"+">"+tekst+L);
}

What went wrong?


You added an erroneous opening brace:

{target=telt();

This should be:

target=telt();

Please look again closely to the example in my previous reply.
JW

Jul 24 '05 #6

P: n/a
Ok, tried again, the function is working but all text after where I run it
on the age is missing.

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}

// Original function body
target=telt();

// I assume wi is defined somewhere?
if (wi==1) {
target="_top";
}

h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+"http://nww."+li
nk+"\",\""+tekst+"\")'"+">"+tekst+L);
}

HN('nix.com/2005/','My Daily Report','DAILY.REPORT.')
------> after this all code on the page is missing....

Marco
"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:42***********************@news.euronet.nl...
Marco Krechting wrote:
I tried the code listed below but it doesn't work:

function HN(link,tekst,clipdata){
// IE only
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}

// Original function body
{target=telt();
if (wi==1)target="_top";

h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+"http://nww."+li nk+"\",\""+tekst+"\")'"+">"+tekst+L);
}

What went wrong?


You added an erroneous opening brace:

{target=telt();

This should be:

target=telt();

Please look again closely to the example in my previous reply.
JW

Jul 24 '05 #7

P: n/a
Marco Krechting wrote:
Ok, tried again, the function is working but all text after where I
run it on the age is missing.

Let's breakdown the function:
target=telt();
Is the telt() function correctly defined?
if (wi==1) {
Is wi defined as a global variable?
h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+
"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L);


Is the h() function correctly defined?

Are the following variables globally defined:

b3
tag
L

Note that when variables not defined globally, should be defined in the
function itself.

BTW, a good JS debugging tool is FireFox's javascript console.
JW

Jul 24 '05 #8

P: n/a
Everything was working fine until I entered the copy clipboard code.

b3 = "<"+"a href='http://nww.";
tag = "target='"
L = "</"+'a><br>';
tel=0;function telt(){tel++;return tel};

I tried to use Firefox JS console, but how do I check a complete html-file?

Marco

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:42***********************@news.euronet.nl...
Marco Krechting wrote:
Ok, tried again, the function is working but all text after where I
run it on the age is missing.


Let's breakdown the function:
target=telt();


Is the telt() function correctly defined?
if (wi==1) {


Is wi defined as a global variable?
h(b3+link+"'"+tag+target+"'"+"onclick='n(\""+targe t+"\",\""+
"http://nww."+link+"\",\""+tekst+"\")'"+">"+tekst+L);


Is the h() function correctly defined?

Are the following variables globally defined:

b3
tag
L

Note that when variables not defined globally, should be defined in the
function itself.

BTW, a good JS debugging tool is FireFox's javascript console.
JW

Jul 24 '05 #9

P: n/a
Marco Krechting wrote:
Everything was working fine until I entered the copy clipboard code.

So everything works fine again when you remove the clipboard code?
I tried to use Firefox JS console, but how do I check a complete
html-file?


Just call the script in FireFox, then look into the JS console to see if
there are errors.
JW

Jul 24 '05 #10

P: n/a
Janwillem Borleffs wrote:
Just call the script in FireFox, then look into the JS console to see
if there are errors.


That is: call the page that includes the script in FireFox. If this doesn't
bring up errors, then post an URL where the page can be viewed somewhere.
JW

Jul 24 '05 #11

P: n/a
Got three time the error: Dialog has no properties

and this one (I don't know what it means):
Error: uncaught exception: [Exception... "Component returned failure
code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.focus]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
chrome://global/content/bindings/tabbrowser.xml :: setFocus :: line
638" data: no]

Marco

Jul 24 '05 #12

P: n/a
ma************@zonnet.nl wrote:
Got three time the error: Dialog has no properties

and this one (I don't know what it means):
Error: uncaught exception: [Exception... "Component returned failure
code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.focus]"
nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
chrome://global/content/bindings/tabbrowser.xml :: setFocus :: line
638" data: no]


Do you programmatically create a popup window anywhere in your code? Does
the script work when you remove the window.clipboardData bit?

The following code works without any problems in both IE and FireFox:

<html>
<head>
<title> New Document </title>
<script type="text/javascript">
function test(text, clipdata) {
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}
document.write(text);
}
</script>
</head>

<body>
<script>test('Hello', 'World');</script>
</body>
</html>

Are you doing something simular or are you calling the HN function when the
page is already done loading? In that case it's important that the h()
function does not use document.write as this will wipe out the initial page
including the scripts.
JW

Jul 24 '05 #13

P: n/a
The problem appears to be that the window.clipboardData.setData() function
expects a string as the second argument and sometimes it's an integer.

Changing the call into:

if (window.clipboardData) {
window.clipboardData.setData('text', '' + clipdata);
}

will fix this...
JW

Jul 24 '05 #14

P: n/a
With this new code it now works fine:

function setClip(clipdata) {
if (window.clipboardData) {
window.clipboardData.setData('text', clipdata);
}
}

function HN(link,tekst,clipdata) {
target=telt();
if (wi==1) {
target="_top";
}

text2write = b3 + link + "'" + tag + target + "'";
text2write += "onclick='setClip(\"" + clipdata + "\");";
text2write +=
"n(\""+target+"\",\""+"http://www."+link+"\",\""+tekst+"\")'";
text2write += ">" + tekst + L;

h(text2write);
}

thanks a lot JW

MArco

Jul 25 '05 #15

P: n/a
Hi ,

This is a very intersting discussion thats going on. Now i tried doing
absolutely the same thing in FireFox and it just did not work. There are
2 things that i tried

1) <script language="javascript" type="text/javascript">

function sendToClipboard(s){

window.clipboardData.setData('text', "123456789");
}

When i do this, i get the follwoing error in the JavaScript Console of
Firefox -:

Error: window.clipboardData has no properties
Source File: file:///C:/Ankur/Test/CopyTest.html
Line: 15

2) And when i try to do something like this -:

<script language="javascript" type="text/javascript">

function sendToClipboard(s){

if( window.clipboardData && clipboardData.setData ){
alert("In the IF loop with s being " + s);
window.clipboardData.setData("Text", s);
}else{

alert("In the ELSE loop ");
}

}
</script>

In this case , it does not even go to the IF loop. It just goes to the
else and comes out.

Any advise will be really appreciated. Thanks in advance

*** Sent via Developersdex http://www.developersdex.com ***
Jul 29 '05 #16

P: n/a
Ankur Vedi wrote:
This is a very intersting discussion thats going on. Now i tried doing
absolutely the same thing in FireFox and it just did not work.


That's the whole idea of the condition; FireFox does not support
window.clipboardData, so you cannot populate data to the clipboard using JS
with this browser...
JW

Jul 29 '05 #17

P: n/a


Hi JW,

Thanks a bunch for your reply and clearing that doubt.

Now if you are saying that window.clipboardData cannot be used with
Firefox, then can you please advise as to how may i achieve the same
functionality in Firefox, ie copying some data on the browser so that i
can paste it later somewhere using Ctrl V .

Thanks Again
Ankur

*** Sent via Developersdex http://www.developersdex.com ***
Jul 31 '05 #18

P: n/a
Ankur Vedi wrote:
Now if you are saying that window.clipboardData cannot be used with
Firefox, then can you please advise as to how may i achieve the same
functionality in Firefox, ie copying some data on the browser so that
i can paste it later somewhere using Ctrl V .


I don't think it is possible in FireFox without a special extension like the
one found at: http://www.gratisdei.com/copytoclip.xpi
JW

Jul 31 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.