The getNFCTag()
method of the MozNFC
interface returns an NDEF tag interface (MozNFCTag
object) used to interact with NFC Tags.
It currently only supports NFC Data Exchange Format (NDEF) compatible NFC tag types, but its functionality will be expanded soon.
Syntax
MozNFCTag getNFCTag(DOMString sessionId);
Example
This example gives an idea of how you can set your activity handler function, then receive a session token from the activity when the function runs and get the NFC tag by passing it to getNFCTag()
:
navigator.mozSetMessageHandler('activity', ndefDiscoveredHandler); function ndefDiscoveredHandler(activity) { var data = activity.source.data; var tag = navigator.mozNfc.getNFCTag(data.sessionToken); console.log(tag instanceof MozNFCTag); // should print true }
Parameters
sessionToken
: The session token associates the web application with the NFC hardware. It's found in the incoming Web Activity's data.sessionToken
property, as seen in the above example.
Returns
A MozNFCTag
object.
Errors
If an invalid session token is passed to getNFCTag()
, it throws the error "Unable to create NFCTag object, Reason: Bad SessionToken".
Specifications
The NFC implementation in Gecko follows the NFC Forum specifications.
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support |
No support |
No support | No support | No support | No support |
Feature | Android | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | No support | 2.0 moz [1] | No support | No support | No support |
[1] Available in privileged apps as of Firefox OS 2.2; certified-only before that.
See also
- Using the NFC API
- Using the NFC emulator
- Related W3C APIs: