Clipboard copy function working

CK CK 3788 
Created at  
3,369 0 0
When copying trackback address or shortcut url on the articles, clipboard function is really useful.
But there are some compatibility issue in browsers.

I checked below function is working on Microsoft Internet Explorer. For supporting Firefox, you need to find another solution.

function copy_clip(meintext){
if (window.clipboardData) {
// the IE-manier
window.clipboardData.setData("Text", meintext);
// waarschijnlijk niet de beste manier om Moz/NS te detecteren;
// het is mij echter onbekend vanaf welke versie dit precies werkt:
} else if (window.netscape) {
// dit is belangrijk maar staat nergens duidelijk vermeld:
// you have to sign the code to enable this, or see notes below
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

// maak een interface naar het clipboard
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip) return;

// maak een transferable
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans) return;

// specificeer wat voor soort data we op willen halen; text in dit geval
trans.addDataFlavor('text/unicode');

// om de data uit de transferable te halen hebben we 2 nieuwe objecten nodig om het in op te slaan
var str = new Object();
var len = new Object();

var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

var copytext=meintext;

str.data=copytext;

trans.setTransferData("text/unicode",str,copytext.length*2);

var clipid=Components.interfaces.nsIClipboard;

if (!clip) return false;

clip.setData(trans,null,clipid.kGlobalClipboard);
}

var msg = alert_msg['url_copy'];
if(typeof(msg)=='undefined'||!msg) return;
alert(msg);
}



Usage sample

<a href=# onclick='copy_clip( "http://kurapa.com"); return false;'>http://kurapa.com</a>

Tags HTML JSP Optimization Javascript java.util javascript clipboard text string copy Facebook X
Comments 0
Similar posts
  1. How to find the ip address of a client machine from a web application?
    518
  2. IFRAME Auto Resize in IE, FireFox by Javascript
    456
  3. Simple RSS Reader based on javascript
    502
  4. How to include Javascript from anonther ?
    412
  5. Javascript based Browser Sniffing
    434
  6. Javascript based Regular Expression Tester
    374
  7. Two useful string functions - substr & substring
    409
  8. Select All, None, Invert checkbox
    507
  9. How to know the browser name in Javascript ?
    640
  10. How to know browser version in javascript ?
    444
  11. Javascript Prompts
    453
  12. Javascript Confirmation
    594
  13. Photo thumbnail viewer implemented in javascript
    487
  14. To get web browser capability
    527
  15. Javascript based query parser for AJAX application
    566
  16. Displays the html tags without rendering on a webpage
    352
  17. To hide/show area of web page without re-loading a page
    1,021
  18. To compare two HTML tables on web page in real time
    515
  19. Photoshop script programming in Javascript
    531
  20. Is there URLEncode function in Javascript ?
    393
  21. Move window
    548
  22. How to calculate page loading time ?
    360
  23. Number Of Vists
    512
  24. Add Message On Mouse Traling
    2,557
  25. Tooltip
    409
  26. Document Fader
    346
  27. Book Mark This Site
    405
  28. Icon Coupled Url
    427
  29. Button That Will Close The Browser Window
    350
  30. Button That Will Show The Page's Source
    388
  1. Java Variant Type
    202
  2. Beyond venv: Java's Project Isolation Strategy
    478
  3. Simple Java Code to display Hello, World on the web
    565
  4. Your Comprehensive Guide to Flink & Kafka for Real-time Stream Processing
    414
  5. Why Java Spring Framework is Considered Optimized for Docker
    1,027
  6. Spring Framework: Evolution, Trends, and Architectural Innovation
    1,260
  7. Java Kafka on CentOS 7: Install, Configure, & Run with Examples
    425
  8. What Replaced JSP? Modern Java Web Dev Explained (with Examples)
    256
  9. Java Maps: HashMap vs. LinkedHashMap vs. TreeMap Explained
    229
  10. How to resize image ?
    1,307
  11. How to set and get sessions on JSP code ?
    1,039
  12. How to add a declaration on JSP code ?
    1,128
  13. How to include file in JSP ?
    1,251
  14. How to print out text strings on HTML directly ?
    905
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    42
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    36
  3. How do I create animated background for Google Meet?
    21,035
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    252
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    515
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    288
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    232
  16. TPU & GPU Cluster Management Tools
    245
  17. The Concept of Scaffolding in AI Agents
    234
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    259
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    222
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    221
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    196
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    219
  30. Understanding Data Lineage
    263