Link mediaProperty
Link Object
Definition and Usage
The media property sets or returns the device for which the document is displayed.
For style information, the target medium is very important. The styles for mobile devices and desktop computers may be different.
Syntax
Set the media property:
linkObject.media="device"
Return the media property:
linkObject.media
deviceCan be the following values:
| Value | Description |
|---|---|
| screen | For non-paginated computer screens. |
| tty | For media using a monospaced character grid (such as typewriters, terminals, or other devices with limited display capabilities). |
| tv | For TV-type devices. |
| projection | For projectors. |
| handheld | For handheld devices. |
| For pages and documents in print preview mode. | |
| braille | For Braille tactile feedback devices for the blind. |
| aural | For speech synthesis. |
| all | For all devices or apparatus. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the media property.
Examples
Examples
The following example gets the media type used by the link element:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<link id="link1" rel="stylesheet" type="text/css" media="screen" href="style1.css.html">
<script>
function displayResult(){
var x=document.getElementById("link1").media;
alert(x);
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">Display media type of link element</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<link id="link1" rel="stylesheet" type="text/css" media="screen" href="style1.css.html">
<script>
function displayResult(){
var x=document.getElementById("link1").media;
alert(x);
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">Display media type of link element</button>
</body>
</html>
Try it Yourself »
Link Object Other Extensions