Cross-origin text Images

Source: Internet
Author: User

Cross-origin text Images

After a small change, you need to display the edited information of another website via Rich Text on the client, including some image content.

There are no other display problems, but the photos cannot be normally displayed. They are always broken image styles.

After debugging, it is found that the image display address is always the hosturl + path of another website. Then, it is found that the database only contains path in Rich Text and does not contain hosturl, therefore, the host address of the local website is automatically added to the image.

Therefore, you must add the path address of the image obtained from the local json content to the hosturl of another website.

The specific implementation method is as follows:

Var json = JSON. parse (content. data); var d = json ["Content"]; // match the image (g indicates matching all results. I indicates case-sensitive) var imgReg =/|\/>)/Gi; // match the src property var srcReg =/src = [\ '\ "]? ([^ \ '\ "] *) [\' \"]? /I; var arr = d. match (imgReg); if (arr! = Null) {for (var I = 0; I <arr. length; I ++) {var src = arr [I]. match (srcReg); // obtain the image address if (src [1]) {var resultImg = mnghost + src [1]; // Add the path in the json content to the address of another server. d = d. replace (src [1], resultImg );}}}

  

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.