Many things are easy to forget, so I chose to record them.
Firefox does not support the obj. innerText attribute.
The value displayed by obj. innerText alert () is undefined.
Firefox supports the innerHTML attribute but does not support innerText. If you do not want to replace innerHTML, you can use the following code:
Because Firefox does not support document. all, document. getelementbyid ('yourid') is usually used to obtain objects for compatibility purposes ').
If (document. all) {// if not IE
// You can also use if (navigator. appName. indexOf ("Explorer")>-1) // obj. innerText = "myText";} else {obj. textContent = "yourtext"; replaced by textContent
}
Javascript code compatible with Firefox and IE copied to the clipboard
When using this function in Firefox, You need to modify a Configuration:
1. Open firefox and enter: about: config in the address bar.
2. Find 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! \ N enter 'about: config' in the address bar of the browser, press enter \ n, and set 'signed. applets. codebase_principal_support 'to 'true ');
}
Var clip = Components. classes ['@ mozilla.org/widget/clipboard=1'mirror.createinstance (Components. interfaces. nsIClipboard );
If (! Clip)
Return;
Var trans = Components. classes ['@ mozilla.org/widget/transferable00001').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-string1_12.16.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 with the same functions.
Function CopyToClipboard (meintext)
{
If (window. clipboardData)
{
// The IE-manier
Window. clipboardData. setData ("Text", meintext );
}
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;
// Alert (clip );
// Maak een transferable
Var trans = Components. classes ['@ mozilla.org/widget/transferable1_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-string1_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 obtain the client computer name
When I learned php a few days ago, I wanted to obtain the client computer name. There are examples of implementation in asp and. net, but I have never found a way to implement it in php. Later, I found some code in a foreign forum, which is javascript. However, it can only run in the IE environment and must be set to a low security level.
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 the current computer name operation denied '+' <br/> ');
}