Javascript源码:
代码如下:
function showImg( url ) {
var imgid = Math.random(),
frameid = 'frameimg' + imgid;
window['img'+imgid] = '<img id="img" src=\''+url+'?kilobug\' /><script>window.onload = function() { parent.document.getElementById(\''+frameid+'\').height = document.getElementById(\'img\').height+\'px\'; }<'+'/script>';
document.write('<iframe id="'+frameid+'" src="javascript:parent[\'img'+imgid+'\'];" frameBorder="0" scrolling="no" width="100%"></iframe>');
}
调用方法:
代码如下:
showImg('图片地址');
完整演示代码: