i have problem that jQuery didnt show up iframe. i have many iframe in my website. when u click link to show up in iframe. but it doesnt show. here my code:
//i load plugin:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script>
开发者_Python百科<script type="text/javascript">
function godirect(url, num)
{
var target = 'iframe_url' + num;
var source = jQuery(target).attr('src');
if (source == "about:blank" || source == "")
{
jQuery(target).attr('src', url);
}
else
{
jQuery(target).attr('src', 'about:blank');
}
}
</script>
PHP & HTML code:
$godirect = 'godirect("'.$GetData['link'].'", "'.$a.'");';
<a href="#" <?php echo $godirect; ?> > TEST LINK </a>
Try this code instead, assuming target
is the ID of the frame element:
var target = 'iframe_url' + num;
var oFrame = $("#" + target);
var source = oFrame.attr('src');
if (source == "about:blank" || source == "")
{
oFrame.attr('src', url);
}
else
{
oFrame.attr('src', 'about:blank');
}
Edit: when initially empty, the src
attribute might be null so try this:
if (source == "about:blank" || source == "" || source == null)
You should place the godirect call in the href-attribute or the onclick-attribute of the anchor. Currently your output looks like this:
<a href="#" godirect("url", "num");>TEST LINK</a>
and should be:
<a href="javascript:godirect("url", "num");">TEST LINK</a>
精彩评论