我有一个博客,我想在加载页面后加载youtube和vimeo视频,因为截至目前这些视频阻止加载其余内容。
这是我为每个帖子生成的代码:
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 :(得分:0)
基本上在javascript变量中捕获generateVimeoVideo($class)()
返回的值,并在dom加载后仅在显示它的页面上创建iframe元素。
答案 1 :(得分:0)
这很简单。
请在点击事件中创建该功能。
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" />
希望它有用!!!
答案 2 :(得分: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>
谢谢,
答案 3 :(得分: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>
答案 4 :(得分: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>