Ejemplo 1: Obtener PHP de resolución de pantalla
// jQUERY FILE
$(function() {
$.post('some_script.php', { width: screen.width, height:screen.height }, function(json) {
if(json.outcome == 'success') {
// do something with the knowledge possibly?
} else {
alert('Unable to let PHP know what the screen resolution is!');
}
},'json');
});
// PHP FILE
<?php
// For instance, you can do something like this:
if(isset($_POST['width']) && isset($_POST['height'])) {
$_SESSION['screen_width'] = $_POST['width'];
$_SESSION['screen_height'] = $_POST['height'];
echo json_encode(array('outcome'=>'success'));
} else {
echo json_encode(array('outcome'=>'error','error'=>"Couldn't save dimension info"));
}
?>
Ejemplo 2: ancho del dispositivo js
window.screen.availWidth
Ejemplo 3: php obtiene el ancho de la pantalla
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = "Total Width: " + screen.width + "px";
document.getElementById("demo").innerHTML = x;
}
</script>
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)