php
  • javascript
  • iframe
  • onload
  • 2013-08-30 47 views 0 likes 
    0

    我有一個博客,我希望youtube和vimeo視頻在加載頁面後加載,因爲截至目前這些視頻阻止加載其餘內容。onload後加載iframe

    這是我爲每一個職位代碼:

    public function generateVimeoVideo($class){ 
    
        return "<iframe class='".$class."' src='//player.vimeo.com/video/".$this->vimeo_video_id."' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"; 
    
    
    } 
    

    如何onload事件後加載此?

    回答

    0

    基本上在javascript變量中捕獲generateVimeoVideo($class)()返回的值,並在您要在加載dom後纔會顯示它的頁面上創建iframe元素。

    0

    這很簡單。

    請在click事件上做功能。

    function change_frame(){ 
    document.getElementById("captchaDiv").src='http://www.domain.com/captcha.php?'+(new Date()).getMilliseconds(); 
    return true; 
    } 
    
    
    <a href='#' onClick="change_frame();return false" /> 
    

    希望它工作!

    0

    它應該像這樣的HTML工作,請檢查並給我回復。

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
    <title>Untitled Document</title> 
    <script type="text/javascript"> 
    <!-- 
    function loadFrame(){ 
    document.getElementById('theframe').innerHTML='<iframe src="http://www.w3schools.com/" width="500" height="300" frameborder="0" scrolling="auto"></iframe>'; 
    } 
    //--> 
    </script> 
    </head> 
    
    <body> 
    <span id="theframe"><noscript><iframe src="http://www.w3schools.com/" width="500" height="300" frameborder="0" scrolling="auto"></iframe></noscript></span><br> 
    The rest of your page here. 
    <script type="text/javascript"> 
    <!-- 
    onload=loadFrame; 
    //--> 
    </script> 
    </body> 
    </html> 
    

    感謝,

    0
    <?php 
    
    
    ?> 
    <html> 
    <body> 
    <script> 
        function generateVimeoVideo($class,$vid){ 
        var putYouTubeHere= document.getElementById('putYouTubeHere'); 
        putYouTubeHere.innerHTML= "<iframe class='" + $class + "' src='//player.vimeo.com/video/" + $vid + "' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>"; 
    
    
    } 
    document.addEventListener("DOMContentLoaded", function(){ generateVimeoVideo('classname','<?php echo $this->vimeo_video_id;?>');}, false); 
    </script> 
    <div id="putYouTubeHere"></div> 
    </body></html> 
    
    0

    試試這個jQuery bind

    <!DOCTYPE html> 
        <html> 
        <head> 
         <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
    
         <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script> 
    
    
         <style type='text/css'> 
         body {background-color:#222;} 
    
        #frameContainer { 
         background:white url('http://hompimpa.googlecode.com/svn/trunk/images/loading.gif') no-repeat 50% 50%; 
         margin:30px; 
        } 
    
        #frameContainer iframe { 
         display:block; 
         padding:5%; 
         border:none !important; 
        } 
    
         </style> 
    
    
    
        <script type='text/javascript'>//<![CDATA[ 
    
        $(window).bind("load", function() { 
         $('#frameContainer').html('<iframe src="//player.vimeo.com/video/" + $vid + " frameborder="0" width="90%" height="220px" scrolling="auto"></iframe>'); 
        }); 
    
        //]]> 
    
        </script> 
    
    </head> 
    <body> 
        <div id="frameContainer"></div> 
    
    
    </body> 
    
    
    </html> 
    
    相關問題