How to get Tencent Video ID _javascript skills

Source: Internet
Author: User

This article illustrates the method of JS acquiring Tencent video ID. Share to everyone for your reference, specific as follows:

Use JS intercept Tencent video ID need to know the address rules, only know the rules can be obtained.

When doing the project encountered the problem of adding video, such as user copy Tencent video link, take this as an example (http://v.qq.com/x/cover/ypdy6korrry8w5a/u0332wyg5oa.html)

Now you need to intercept. html front and last slash behind the content (U0332wyg5oa), Tencent video click to share the following code will appear:

Copy Code code as follows:
<iframe frameborder= "0″width=" 640″height= "498″src=" http://v.qq.com/iframe/player.html?vid=u0332wyg5oa& Tiny=0&auto=0″allowfullscreen></iframe>

Find the "vid=" inside SRC, and the code inside is the same as the video ID we want to intercept. So I summarized the following methods to intercept the video ID, the method is not simple, is a step-by-step interception, welcome friends to make comments or suggestions (mobile phone or PC-side links can be).

$ (function () {
//Tencent video Pc-side URL
var video_pc_tx = ' http://v.qq.com ';
Tencent video mobile end-end URL
var video_mobile_tx = ' http://m.v.qq.com ';
Click event
$ ("#video_Url"). Click (function () {
//Get the value in the input box
var Video_url = $ ("#demo"). Val ();
var video_url_id = ";
if (Video_url.indexof (VIDEO_PC_TX)!=-1) {
//intercept Pc-side video Id
var pc_tx_id_w = video_url.substr (0,video_ Url.lastindexof ('. ') -1);
video_url_id = Pc_tx_id_w.substr (Pc_tx_id_w.lastindexof ('/') +1,pc_tx_id_w.length);
} else {
//At this point may be mobile end Tencent video or Youku video
if (Video_url.indexof (VIDEO_MOBILE_TX)!=-1) {
/**
* Here is the Judge mobile end video link
* getquerystring ()//Call function gets video ID/function
getquerystring (name) {
var reg = new RegExp ("^|& ) "+ name +" = ([^&]*) (&|$));
var r = video_url.substr (1). Match (reg);
if (r!=null) return unescape (r[2]); return null;
}
Intercepting PC-side video Id
video_url_id = getquerystring ("vid");}});


Then "video_url_id" is the Id of the video so you can put it into the "vid=" Inside "src".

can also be encapsulated into a function, directly call on the line;

Like what:

function Datavideo (URL) {
//above code return
video_url_id
}

Called directly when the

video_url_id = Datavideo (URL);

It's okay.

More readers interested in JavaScript-related content can view this site: "JavaScript in the JSON Operation tips Summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"

I hope this article will help you with JavaScript programming.

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.