Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code won't get called! Arrrggg!!!

Status
Not open for further replies.

ppetree

Programmer
Mar 3, 2007
60
US
I've screwed around with this for two hours and can't get this javascript function to get called! I must be missing something here! Extra eyes would be GREATLY appreciated!

Here is my html code:
Code:
<html>
<head>
<link rel="StyleSheet" href="/javascript/coolstyle.css" type="text/css">

<script language="JavaScript" type="text/javascript" src="/javascript/pop-closeup.js"></script>
<script language="JavaScript" type="text/javascript" src="/javascript/javascripts.js"></script>
<script language="JavaScript" type="text/javascript" src="/javascript/clipboard.js"></script>
</head>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<center>
To use the following code, simply cut and paste into<br>
your html document exactly as you see it here.<br>
<br>
<textarea name="html_code" cols="60" rows="6">Cut and Copy this Text
</textarea>
<button onclick="javascript:copyToClipboard(document.getElementById('html_code').value);">Copy To Clipboard</button>
<button onclick="javascript:copyToAlert('Hello World!');">Copy To Alert</button>
<button onclick="alert('Hello World!');">This works fine!</button>
</center>
</body>
</html>

Here is my javascript:clipboard.js file:
Code:
function copyToAlert(s)
{
  alert("Text to Copy: \n" +s);
}

function copyToClipboard(s)
{
  alert("Hello World!");  

  if( window.clipboardData && clipboardData.setData )
  {
    clipboardData.setData("Text", s);
  }
  else
  {
    .
    .
    .
  }
}
 
Whew! I feel like a dog chasing his tail!

Ok, changing the <script src= tag to the full path name did not change any results.

Adding a <base href=" tag and setting the <script src="/javascript/clipboard.js" produced this in the Firefox DCOM Inspector: src=
With the <base> tag removed DCOM inspector showed the source as: Which is the correct path!

I did see this error twice, no idea what it means.
Error: No chrome package registered for chrome://communicator/content/utilityOverlay.xul .

I also did get an error saying the copyToClip function was not defined.
 
I didn't look at the file itself, but found one line missing an equals sign:
Code:
var clip [b][red]=[/red][/b] Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
 
Hey Dan!

No, I had missed your previous post.

Here's what I did:
1) deleted the existing clipboard.js
2) created a new clipboard.js which contained one function called copyToClipbard and it contained a simple alert()
3) this worked.

So I started adding code:
1) I added the support for IE copy and that worked;
2) I added support for the mozilla copy and it failed;
3) I made the edits you suggested and that still failed in mozilla but worked in IE
4) Found some new/better code for mozilla from the mozilla sdk reference (online), tried that and it did not work in Firefox;
5) Gave up on supporting that functionality in mozilla or netscape browsers (since the boss says we're a M$ shop)

The problem seems to be that the java interpreter can't parse out [[[[1]]]] and since it encounters an error it fails to register the function with the DOM.

Thanks for all your help!

Phil

Thanks for all your help!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top