How to obtain Lrc lyrics data from a browser across domains

Source: Internet
Author: User

You can use the XMLHTTP component or IFRAME to obtain data from the same domain. This is simple because there is no cross-origin access permission problem.
However, to access data in different domains, XMLHTTP does not have the permission to obtain data due to browser security settings, and IFRAME does not have the permission to pass the obtained data to the parent window, there seems to be no other solution.

Epiphany ......
Scripts that reference different domains on the webpage do not prompt insufficient permissions. By the way, it is true!

The solution is found. Now let's test it briefly:

First, create a page (test.html) on the 51js.comserver ).

<Html> <pead> <title> Over-Domain Data Fetching Test Page </title> </pead> <body> <button onclick = "loadScript ('HTTP: // aboutplayer.com/alert.js') "> Test Alert </button> <button onclick =" loadScript ('HTTP: // aboutplayer.com/info.js') "> Get My Info </button> My Name: <input id = "myname" type = "text" value = ""> My Blog: <input id = "myblog" type = "text" value = ""> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Two key points are explained:
1. lastScript is used to store the ID of the last created script node. When you create another script node next time, you need to delete the last created node to avoid loading more scripts and occupying too much memory.
2. A value d is added to the url to prevent the browser from caching script data. In this example, the value d is not added. However, if the script is dynamically generated by the server, it is best to add it.

Then create two java script scripts for testing.

Alert. js:
Alert ('You can see me! ');
Info. js:
G ('myname'). value = 'music audience ';
G ('myblog'). value = 'www .aboutplayer.com ';

After all, music has put the followers in the aboutplayer.comserver, and test.html are not in the same domain.

Open the test.html file with a browser.
Click "Test Alert". The displayed dialog box is displayed !.
Click "Get My Info". The information on this site is displayed in the text box.

Then, if you put the Lrc lyrics data into the Js script file (instead of directly changing the file extension), you can obtain the Lrc lyrics data across domains.

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.