简体   繁体   中英

Javascript bringing specific div of external file

Im using fancybox to load a video within iframe. And i need to create one .php file for each video. Is it possible to put all videos in same file and bring only a specific div where video are and i want?

$(".iframe").fancybox({
    'beforeLoad' : function(){
    var url= $(this.element).data("href");
    this.href = baseURL+'assets/media/mp4/'+url+'.php'
    }
});

MY external divs

<div id="MBHD0790-04"> 
    <video>
        <source src="~source~/MBHD0790-04.mp4" type="video/mp4">
    </video>
</div>
<div id="MBHD0790-03">
    <video>
        <source src="~source~/MBHD0790-03.mp4" type="video/mp4">
    </video>
</div>
<div id="MBHD0790-02"> 
    <video>    
        <source src="~source~/MBHD0790-02.mp4" type="video/mp4">
    </video>
</div>

My VIEW

<a href="javascript:;" data-href="MBHD0790-04" id="MBHD0790-04" class="iframe">
    GETVIDEO
</a>

Instead of:

this.href = baseURL+'assets/media/mp4/'+videoid+'.php' 

Do this:

this.href = baseURL+'assets/media/mp4/video.php?videoId='+videoid

Then all you need to create is a video.php file that would display the appropriate HTML. The most simple example:

<?php
    switch ($_GET['videoId'])
    {
         case 'one':
             echo '<div>content of video div with id=one</div>';
             break;
         case 'two':
             echo '<div>content of video div with id=two</div>';
             break;
         ...
    }
?>

This could obviously be optimized with loops, arrays etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM