jQuery 函数在新窗口中打开链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16570149/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:22:34  来源:igfitidea点击:

jQuery function to open link in new window

javascriptjquerypopupwindow

提问by jenhan

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.

我试图找到一个插件或简单的脚本来通过单击按钮在弹出窗口中打开文件。这曾经有效,但随着所有 jQuery 更新(即使是迁移文件),这不再有效。

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

我找到了这个,但这会打开弹出窗口并重定向到文件 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.

我还想避免添加任何额外的标记。只添加一个类是最有意义的,就像上面的例子一样。

回答by Chamika Sandamal

Try this,

尝试这个,

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

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

你必须包含 jQuery 参考来工作,这里是工作样本 http://jsfiddle.net/a7qJt/

回答by Murali P

Button click event only.

仅按钮单击事件。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                $("#btnext").click(function () {                    
                    window.open("HTMLPage.htm", "PopupWindow", "width=600,height=600,scrollbars=yes,resizable=no");
                });
            });
</script>

回答by computerguy

http://www.jquerybyexample.net/2012/05/open-link-in-new-tab-or-new-popup.html

http://www.jquerybyexample.net/2012/05/open-link-in-new-tab-or-new-popup.html

$(document).ready(function() {
$('A.BLAH').click(function() {
var NWin = window.open($(this).prop('href'), '', 'height=600,width=1000');
if (window.focus)
{
NWin.focus();
}
return false;
});
});

回答by Mohammad Adil

Try adding return false;in your click callback like this -

尝试return false;像这样添加您的点击回调 -

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

回答by dfsdf

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