我正在使用jQuery在新窗口中打开一个链接:
<script type="text/javascript">
$(document).ready(function() {
$('a[href="/education/global-health-courses"]').attr("target", "_blank");
});
</script>
我想将新窗口的大小设置为800px宽,700px高。我只需要帮助将这些属性添加到现有代码中。
感谢。
答案 0 :(得分:11)
您无法使用target="_blank"
方法设置这些属性,您必须使用window.open方法:
$(document).ready(function() {
$('a[href="/education/global-health-courses"]').click(function() {
window.open($(this).attr('href'),'title', 'width=800, height=700');
return false;
});
});
答案 1 :(得分:1)
您无法调整target=blank
窗口AFAIK的大小。
您必须使用window.open
创建一个新的 - 例如,在this article中 - 并添加testwindow.resizeTo(x,y)
命令以确保。
答案 2 :(得分:1)
一种很好的方法是使用带有colorbox(http://colorpowered.com/colorbox/)
的iframe$('a[href="/education/global-health-courses"]')
.colorbox({width:"80%", height:"80%", iframe:true});
答案 3 :(得分:0)
要设置窗口大小,您需要使用window.open方法。您可以订阅target="_blank"
事件并致电click
,而不是在锚点上使用window.open
。
答案 4 :(得分:0)
如果你真的想要很好地控制外观和行为,我强烈建议使用名为ShadowBox的脚本。它是最稳定和多功能的模态窗口javascript脚本。您可以使用该脚本在弹出div(包含iframe)内启动外部页面。