duanlin6989 2014-05-04 07:15
浏览 28
已采纳

使用javascript将空白变量发布到移动网站

I want to redirect users to a mobile version of my website.

The redirect works fine, however the php variables are not passing.

I am using the following:

<script>
if ($(window).width() < 480 || $(window).height() < 480) {
var searchproducts = "<?php $_GET['search']?>";
var category = "<?php $_GET['cat']?>";

var page="http://m.website.com/search.php?search="+searchproducts+"&cat="+category;
document.location.href=page;

}
</script>

I have also tried:

<script>
if ($(window).width() < 480 || $(window).height() < 480) {
window.location.replace("http://m.website.com/search.php?search=<?php $_GET['search']?>&cat=<?php $_GET['cat']?>");

}
</script>

Can anyone help?

Thanks

  • 写回答

2条回答 默认 最新

  • dozc1071 2014-05-04 07:16
    关注

    You need to add the echostatement..

    var searchproducts = "<?php echo isset($_GET['search']) ? $_GET['search'] : 'Nothing'; ?>";
    var category       = "<?php echo isset($_GET['cat']) ? $_GET['cat'] : 'Nothing'; ?>";
    

    Also, use an isset construct as shown.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?