The magical application of IndexOf method in JavaScript

Source: Internet
Author: User

Syntax for indexOf methods in javascript: Thestring.indexof (Substring,[n]). It looks for a routed substring in the specified string object, and if you specify parameter n, it can start the search forward (from left to right) from the specified position. Returns the position of the substring in the string if a substring is found, or 1 if no corresponding string is found.

Using this property, we can call it a lot of work, as long as you command it properly.

First, the evaluation of the OS

Although the HTTP protocol is cross-platform, the final display of HTML pages you write is often related to the operating system used by the client. For example, the MSOs series (Ms-dos,windows 9x/nt, etc.) for the text "another line" is defined as "carriage return add line", but the Mac as long as a "return" is enough, and Unix/linux only use "line break". This way you can export some of the things you want to branch in a certain page that may result in a "compatibility" problem ... Okay, look at the following example:

First step: Insert the following script at a location in the page:

Step two: On the page body (...). ) is used in:

Second, judge the browser

Browser compatibility issues have been plagued by the vast number of Web page writers, there are many solutions to this problem, but I think the most thorough, most effective measures for each major browser to write a page version, which is almost perfect. Try the following code, which will help you bring your visitors to the page that corresponds to the client browser:

...... Between-->

Third, determine the location of the page

Now online "copy + paste" method is very popular, we also have no way to let their own site is not copied, but some people are too lazy, they even copy time are reluctant to spend, directly to your page frame to their page to the ... Of course, you can also use the method of judging the frame name to prevent this problem, but if your page is to be used by many frames page, this is not more stupid? Look at the following simple and short code, I believe it will be useful ... Between-->

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.