开发者

mobile safari white background

I'm creating a web app exclusively for the iPad/mobile-Safari. The homepage is a run-of-the-mill HTML/CSS page with 3 main sections. But once you click on either of the 3 main buttons, you are directed to a page constru开发者_JAVA百科cted with 2 iFrames (one on top for Nav, one on bottom for Content)

The problem was that before either of these 3 pages loaded there was a quick flash of white color and then the page loaded. I tried hiding the visibility style of the iframe and then onLoad change it to 'visible' and that worked. But it worked only once, when the iFrame-constructed page first loads. Once it loads and I click on a link on that page, the white flash is back because the iFrame has loaded already so it's already visible.

I tried the obvious like adding a css style to the iframe with a background color (also tried an inline style) but the same thing happened. Any ideas on how to solve it? Thanks!


You can do this cheat:

<iframe src="..." style="visibility:hidden;" onload="this.style.visibility='visible';"></iframe>

In the content, you can catch all link and form:

document.getElementsByTagName("a").addEventListener("click", function(e){
    window.top.document.getElementsByTagName("iframe")[0].style.visibility = "hidden";
});

Explain:

  • First time, your iframe is hidden, and you can see the background of your main page (not white of iframe)
  • After loaded, Javascript will make iframe is visible and you can see content and background of iframe.
  • When click a link inside iframe, a trigger will fire, and Javascript will hide iframe again.

I met that problem, and that a whole day to trying to fix, but I cannot except above way. You can meet that issue on Chrome, Firefox, and other browsers, not just on Safari Mobile.


I think the same with KimKha. But "visibility" does not work well sometimes, so I think using "opacity" is better.

<iframe src="..." style="opacity:0;" onload="this.style.opacity=1;"></iframe>


I came across this issue, found lots of solution like KimKha mentions..

None of the solutions assist in further page transitions in the iframe and hiding it really is not a good solution.

With lots of trail and error I came up with the following which fixed my IOS webkit iFrame transition white flash issue, ironically it's such a simple solution:

Just add this to your CSS

html{background:#000}

change the colour to your desired color.

It looks like what the ultimate issue with IOS webkit is when your iframe calls another page, IOS removes the body from the current page for a split second before rendering the content from the new page. by forcing the HTML to have the background colour (default will naturally be white) this fixes the white flicker.

Also note that if your server is set to not allow caching of the .css file providing the styles then you will always get the flicker.

In apache to ensure caching look at

ExpiresByType text/css "access plus 30 days"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜