Javascript 在 div 标签内打开 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8905862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open URL inside a div tag
提问by Adeel Aslam
I have a div tag inside a table cell and and a hyperlink tag in another cell and on i want open a specific url onmouseover on hyperlink inside the div tag.the url is to my pdf file.Please anyone tell me how can i do this thorugh Javascript or anyother method
我在表格单元格中有一个 div 标签,在另一个单元格中有一个超链接标签,我想在 div 标签内的超链接上打开一个特定的 url onmouseover。该 url 是我的 pdf 文件。请任何人告诉我我该怎么做通过 Javascript 或任何其他方法
回答by jerjer
Something like this:
像这样的东西:
<table>
<tr>
<td>
<a href="/pdfs/test1.pdf" onmouseover="previewUrl(this.href,'div1')">google</a>
</td>
<td>
<div id="div1" style="width:400px;height:200px;border:1px solid #ddd;"></div>
</td>
</tr>
</table>
<script>
function previewUrl(url,target){
//use timeout coz mousehover fires several times
clearTimeout(window.ht);
window.ht = setTimeout(function(){
var div = document.getElementById(target);
div.innerHTML = '<iframe style="width:100%;height:100%;" frameborder="0" src="' + url + '" />';
},20);
}
</script>
回答by Sudhir Bastakoti
If you mean you want to open a new page on mouse over, then:
如果您的意思是要在鼠标悬停时打开一个新页面,则:
//add onmouseover to your hyperlink
<a href="#" onMouseOver="open_new_window(url);">Open Hover Window
//then js
function open_new_window(url) {
window.open(url,"some_name","width=300,height=200,left=10,top=10");
}
Did you mean something like that
你是不是这个意思