Reputation: 17
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>
Upvotes: 0
Views: 2569
Reputation: 11987
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>
Upvotes: 1