I have 2 files abc.php and xyz.php. When i open in mobile, it includes abc.php and on desktop xyz.php is included. I have included these files below but it's not working. Any suggestions welcome.
<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
<?php include ('abc.php');?>
} else {
<?php include ('xyz.php');?>
}
</script>
PHP is server side language. You cannot load like that.
So use ajax instead.
<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
var include = "abc.php";
} else {
var include = "xyz.php";
}
$.ajax({
url:"url to a function where you can include specified file",
type:"POST",
data:{file: include},
success: function(){
// you can get executed content of a file here.
}
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.