jQuery函数在新窗口中打开链接 [英] jQuery function to open link in new window

查看:103
本文介绍了jQuery函数在新窗口中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图找到一个插件或简单的脚本,以通过单击按钮在弹出窗口中打开文件.以前可以使用,但是对于所有jQuery更新(即使使用迁移文件),也不再可用.

I'm trying to find a plugin or simple script to open a file in a popup window by clicking on a button. This used to work, but with all the jQuery updates (even with the migration file), this no longer works.

我找到了,但这会打开弹出窗口,并且还会重定向到文件url:

I found this, but this opens the popup and also redirects to the file url:

$(document).ready(function() {
$('.popup').click(function(event) {
    window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes");
 });
});

有什么方法可以得到一个简单的弹出窗口?它需要有滚动条,最好是可调整大小的.我已经看到了很多关于模态框的文章,但这并不能满足我的需要.弹出框具有自己的设计,并且包含的​​内容超过适用于模式的内容.

Any way to get a simple popup? It needs to have scrollbars, preferably resizable. I've seen lots of posts for modal boxes, but that does not accomplish what I need. The popup box has it's own design and there is more content than would be suitable for a modal.

我也想避免添加任何额外的标记.像上面的示例一样,仅添加一个类是最有意义的.

I also want to avoid adding any extra markup. It makes the most sense to just add a class, like the example above.

推荐答案

尝试一下,

$('.popup').click(function(event) {
    event.preventDefault();
    window.open($(this).attr("href"), "popupWindow", "width=600,height=600,scrollbars=yes");
});

您必须包含jQuery参考才能进行此操作, 这是工作样品 http://jsfiddle.net/a7qJt/

You have to include jQuery reference to work this, here is the working sampe http://jsfiddle.net/a7qJt/

这篇关于jQuery函数在新窗口中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆