答案 0 :(得分:38)
您可以使用iframe在鼠标悬停时显示页面预览。
http://jsbin.com/urarem/3/edit
HTML:
This live preview for <a href="http://en.wikipedia.org/">Wikipedia</a><div class="box"><iframe src="http://en.wikipedia.org/" width = "500px" height = "500px"></iframe></div> remains open on mouseover.
CSS:
.box{
display: none;
width: 100%;
}
a:hover + .box,.box:hover{
display: block;
position: relative;
z-index: 100;
}
答案 1 :(得分:12)
您可以使用以下代码使用javascript显示链接的实时预览。
<embed src="https://www.w3schools.com/html/default.asp" width="60" height="40" />
<p id="p1"><a href="http://cnet.com">Cnet</a></p>
<p id="p2"><a href="http://codegena.com">Codegena</a></p>
<p id="p3"><a href="http://apple.com">Apple</a></p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<link href="http://codegena.com/assets/css/image-preview-for-link.css" rel="stylesheet">
<script type="text/javascript">
$(function() {
$('#p1 a').miniPreview({ prefetch: 'pageload' });
$('#p2 a').miniPreview({ prefetch: 'parenthover' });
$('#p3 a').miniPreview({ prefetch: 'none' });
});
</script> <script src="http://codegena.com/assets/js/image-preview-for-link.js"></script>
&#13;
在are
了解详情id="p1" - Fetch image preview on page load.
id="p2" - Fetch preview on hover.
id="p3" - Fetch preview image each time you hover.
答案 2 :(得分:2)
就个人而言,我会避免使用iframe并使用embed标签在鼠标悬停框中创建视图。
<embed src="http://www.btf-internet.com" width="600" height="400" />
答案 3 :(得分:1)
我做了一个小插件来显示iframe窗口来预览链接。 仍在测试版。 也许它适合你的情况:https://github.com/Fischer-L/previewbox。
答案 4 :(得分:1)
答案 5 :(得分:1)
添加带有链接预览的弹出窗口的最简单、最快捷的方法是集成 Linkz.ai 脚本。
<script src="https://js.linkz.ai/?key=XXXXXXXXXXXX"></script>
这也是所有答案中性能最高的解决方案:
答案 6 :(得分:0)
您可以执行以下操作:
当然这实际上并不存在。
更明智的是,您可以为某些网址生成预览图片,例如每天或每周使用它们。我想您不想手动执行此操作,并且您不希望向您的服务用户显示与网站当前外观完全不同的预览。
答案 7 :(得分:0)
HTML 结构
<div id="app">
<div class="box">
<div class="title">How to preview link with iframe and javascript?</div>
<div class="note"><small>Note: Click to every link on content below to preview</small></div>
<div id="content">
We'll first attach all the events to all the links for which we want to <a href="https://htmlcssdownload.com/">preview</a> with the addEventListener method. In this method we will create elements including the floating frame containing the preview pane, the preview pane off button, the iframe button to load the preview content.
</div>
<h3>Preview the link</h3>
<div id="result"></div>
</div>
我们将首先使用 addEventListener 方法将所有事件附加到我们想要预览的所有链接。在此方法中,我们将创建元素,包括包含预览窗格的浮动框架、预览窗格关闭按钮、加载预览内容的 iframe 按钮。
<script type="text/javascript">
(()=>{
let content = document.getElementById('content');
let links = content.getElementsByTagName('a');
for (let index = 0; index < links.length; index++) {
const element = links[index];
element.addEventListener('click',(e)=>{
e.preventDefault();
openDemoLink(e.target.href);
})
}
function openDemoLink(link){
let div = document.createElement('div');
div.classList.add('preview_frame');
let frame = document.createElement('iframe');
frame.src = link;
let close = document.createElement('a');
close.classList.add('close-btn');
close.innerHTML = "Click here to close the example";
close.addEventListener('click', function(e){
div.remove();
})
div.appendChild(frame);
div.appendChild(close);
document.getElementById('result').appendChild(div);
}
})()
查看详细信息