Throughout much of its history China has remained an insular and isolated civilization, largely ignoring - and ignored by - the rest of the world. This was not difficult, as for many centuries China long held a distinct technological and military edge over any and all external foes. And any threats it could not defeat militarily (such as the Mongols, who conquered China in 1271), it simply absorbed into its own dominant culture.
This changed during the 18th and 19th centuries. By this period, the European powers and Japan had achieved a significant technological advantage over the Chinese. This edge, combined with vastly superior naval forces, better armaments, superior communications and advanced military tactics, allowed the foreign powers to dominate much of the rich Chinese coastal cities, where they could engage in extremely profitable business (including the infamous opium trade). The weak and corrupt Chinese central government was unable to oust the hated foreigners, who remained until most were driven out by the Japanese during and following World War II.