0

I have created a website which works well on the desktop, but on iPhone and iPad background images are not shown.

I have tried deleting the php script that chooses the image and re-written the code to use javascript to set the background and in this case the background is showed correctly.

This is the php code that chooses the image:

<?php
//if  doesn't exist, open the session
if(!isset($_SESSION))
{
    session_start();
}
//set coockie
setcookie("allweb","connected", time()+3600);
//if doesn' exist yet, I create a new array
if(!isset($_SESSION['arrayImage'])){
    $arrayImage = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
}else{// else I get from sessiom
    $arrayImage = $_SESSION['arrayImage'];  
}
//if already exist variable $picture, increment it
if(isset($_SESSION['picture']) && isset($arrayImage)){
    $picture=$_SESSION['picture'];
    $picture = $picture + 1;
    $_SESSION['picture'] = $picture;//save picture
}else{// else I create it
    $picture = 1;
    $_SESSION['picture'] = $picture;// save it
    shuffle($arrayImage);// I shuffle the array
    $_SESSION['arrayImage'] = $arrayImage;//save array to the session
}
?>

and in the php pages i have this code between the style tags:

<style type="text/css">
<?php 
if($picture < 15){//if I'm not out fo bound I continue
    echo 'body {background-image:url("images/bg'.$arrayImage[$picture].'hq.jpg");}';
}
else{// else I set picture to default value and restar the loop.
    $picture = 0;
    $_SESSION['picture'] = $picture;// save it
    echo 'body {background-image:url("images/bg'.$arrayImage[$picture].'hq.jpg");}';
}       
?>      
</style>

The problem is that the images are not showed immediately but I have to zoom the pages then they appear.

4

1 回答 1

0

我假设您已经检查了输出并且它是正确的。如果是这种情况,请尝试从背景 url 中删除引号:

body {background-image:url("images/bg'.$arrayImage[$picture].'hq.jpg");}

body {background-image:url(images/bg'.$arrayImage[$picture].'hq.jpg);}

顺便说一句,使用它们是绝对有效的,但这种情况很少见,即使使用有效的标记,iOS 的 Webkit 渲染器有时也会产生一些非常错误的结果。不幸的是,它不同于 Android 的 Webkit 渲染器或任何 x86 Webkit 引擎,因此如果没有非常昂贵的 Apple 设备,这些问题就无法重现和深入检查。

使用 JS 完成的 CSS 修改,特别是框架(例如 jQuery)通常会智能解析,从而在需要时进行语法更正,所以这就是为什么那些引号是我的主要嫌疑人。

于 2013-04-19T06:06:22.833 回答