링크를 클릭 할 때 Iframe의 src 값을 변경하고 href를 사용하여 값을 변경하려고합니다. 버튼을 클릭하면 기본 동작을 방지하고 src 값을 url로 바꿉니다. 이 코드는 URL이 아닌 값을 사용하여 iframe에서 페이지를 찾을 수 없도록 표시하지만 유효한 URL이 제공되면 작동하지 않습니다. 다음은 사용중인 페이지의 코드입니다.Jquery로 attr 값 변경하기
이 내가 사이트를
$.ajaxSetup ({
cache: false
});
$(document).ready(function(){
$('.pageContent').load('home.php');
setInterval("changePage()",250);
});
function changePage(hash)
{
$('.youtubeLink').click(function(e) {
e.preventDefault();
var temp = $(this).attr("href");
//alert (temp);
$('#youtubePlayerFrame').attr('src', temp);
//when using var temp no action occurs
//when testing temp, it does hold the url, if i replace temp with a string such as
//'asdasd' the script works correctly but replaces the frame with a 404 error
})
$(window).hashchange(function(){
if(!hash) hash=window.location.hash;
hash = hash.replace('#','');
if (hash =='')
{
$('.pageContent').load('home.php');
}
}
else
{
$('.pageContent').load(hash + '.php');
hash = null;
}
})
}
이 코드를 실행하는 데 사용 된 주요 스크립트는이 마지막 코드에 대한 PHP 파일 인 유튜브 플레이어
<?php
echo '
<div class="youtubePlayer" >
<iframe width="420" height="315" id = "youtubePlayerFrame" src="http://www.youtube.com/embed/j8Szl_JyCUQ" frameborder="0" allowfullscreen style="margin-top:34px; margin-left:20px;"></iframe>
</div>
';
include 'sideDirectory.php';
include 'sideMenu.php';
?>
을 보유하고있는 주요 사업부입니다 링크와 디렉토리
<?php
echo'
<div class="sideDirectory">
<table><tbody>
';
$file = fopen("../data/recentlyAdded.txt","r");
$linksFile = fopen("../data/links.txt","r");
while($line =fgets($file))
{
$url = fgets($linksFile);
// echo '<tr><td>' .$url. '</td></tr>';
echo '<tr><td><a class="youtubeLink" href="'.$url.'">'.$line.'</a></td></tr>';
}
fclose($file);
fclose($linksFile);
echo '
</tbody> </table>
</div>
';
?>
신성한 허튼 소리, 매초 네 번씩 새 클릭 이벤트를 바인딩하고 있습니다. 어떻게 그 일을 해나나요? – adeneo
WAAHHHH! 그것은 iframe입니다. 이것은 브라우저 나 다른 무언가의 동일한 출처 정책과 관련이 있을까요? – Gijs
앵커 태그가 * if * target입니까? 'target = "iframeid"' –