How to set the title_javascript technique of micro-browser in iOS

Source: Internet
Author: User

When it comes to Web front-end, browser differences are an unavoidable problem, and this time the project encounters the following problems:

The contents of the micro-beacon navigation bar are set by the title of the item directly taken. But now do the project is a single page application, the entire page will only be completely refreshed for the first time, only local refresh, so only in the page refresh through JS dynamic change title. We started using the following procedure:

Document.title = "What the micro-beacon navigation bar wants to display";
$ ("title"). Text ("What the micro-beacon navigation bar wants to display");
document.getElementsByTagName ("title") [0].innertext = "What the micro-navigation bar wants to display"

The above method is simple and convenient, but the above method has no problem with Android, but iOS micro-browser is invalid.

Workaround:

var $body = $ (' body ');
Document.title = ' The title you want to set ';
var $iframe = $ ("<iframe style= ' display:none; ' src= '/favicon.ico ' ></iframe>");
$iframe. On (' Load ', function () {
settimeout (function () {
$iframe. Off (' Load '). Remove ();
}, 0);
}). Appendto ($body);

The principle is relatively simple, before the micro-trust browser first loaded page initialization title, it will no longer listen to the document.title change events. After modifying title here, add an iframe with an empty content to the page, then delete the iframe immediately, and then refresh the title. However, when the IFRAME is loaded and deleted, the iOS page will have a few milliseconds of flashing (there is a gray box), Android directly has a gray box appears in the page does not disappear, so, the first load of the IFRAME, the style of the IFRAME is set to: Display:none; This solves the problem, and because display:none this setting, the IFRAME is detached from the text stream, loading and deleting this iframe will not change the text stream, nor will it trigger the page rendering.

The above is a small set of JS to introduce how to configure the iOS in the micro-letter browser title, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.