Record several JavaScript-related little details _javascript tips

Source: Internet
Author: User
Tags learn php
A lot of things are easy to inadvertently forget, so I choose to record down.

Firefox does not support Obj.innertext properties.

The value shown by Obj.innertext alert () is undefined.

Firefox supports InnerHTML properties but does not support innertext, if you do not want to use innerHTML substitution, you can use the following code

Since Firefox does not support document.all, it is usually document.getElementById (' Yourid ') to get objects when considering compatibility.


if (document.all) {//If not IE
You can also use if (Navigator.appName.indexOf ("explorer") >-1)//Obj.innertext = "MyText";} else {obj.textcontent = "yourtext"; Replace with Textcontent
}

Firefox, IE compatible copy to clipboard JavaScript code

This function needs to be modified under Firefox with a configuration:
1. Open Firefox, enter in the Address bar: About:config
2. Locate the Signed.applets.codebase_principal_support and set the value to True


function CopyToClipboard (TXT) {

if (Window.clipboarddata)
{
Window.clipboardData.clearData ();
Window.clipboardData.setData (Text, TXT);
}
else if (navigator.userAgent.indexOf (Opera)!=-1)
{
window.location = txt;
}
else if (window.netscape)
{
try {
Netscape.security.PrivilegeManager.enablePrivilege (Universalxpconnect);
}
catch (E)
{
Alert (!! Rejected by the browser! \ nplease type ' About:config ' in the browser address bar and enter \ n then set ' Signed.applets.codebase_principal_support ' to ' true ';
}
var clip = components.classes[' @mozilla. Org/widget/clipboard;1 '].createinstance ( Components.interfaces.nsIClipboard);
if (!clip)
Return
var trans = components.classes[' @mozilla. Org/widget/transferable;1 '].createinstance ( Components.interfaces.nsITransferable);
if (!trans)
Return
Trans.adddataflavor (' Text/unicode ');
var str = new Object ();
var len = new Object ();
var str = components.classes[@mozilla. Org/supports-string;1].createinstance ( Components.interfaces.nsISupportsString);
var copytext = txt;
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);
}
return true;
}

or use the following code, the same function.

function CopyToClipboard (meintext)
{
if (Window.clipboarddata)
{
The Ie-manier
Window.clipboardData.setData ("Text", Meintext);
}
else if (window.netscape)
{
The DIT is Belangrijk maar staat nergens Duidelijk Vermeld:
You are have to sign the code to enable this, or the 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;
alert (clip);
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);
}
Else
{
return false;
}

Alert ("You have copied:" + meintext);
return false;
}

Use JavaScript to get client computer names

A few days ago to learn PHP to achieve the client computer name, both in ASP and. NET have implemented examples, but has not found a way to implement the method in PHP. Later in the foreign Forum found some code, is JavaScript. But it can only run in the IE environment, and the security level must be set fairly low.

Try
{
var ax = new ActiveXObject ("Wscript.Network");
document.write (' User: ' + ax. UserName + ' <br/> ');
document.write (' Computer: ' + ax.computername + ' <br/> ');
}
catch (E)
{
document.write (' access to current computer name Operation denied ' + ' <br/> ');
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.