-4

我对 jquery 有以下问题:

$(function() {

    var linkCorretto = $("#id").text();
    var authWindow;

    $('a[data-reveal-id]').live('click', function(e) {
        e.preventDefault();
        var modalLocation = $(this).attr('data-reveal-id');
        $('#' + modalLocation).reveal($(this).data());
    });

    $.fn.reveal = function(options) {

        var defaults = {
            animation: 'fadeAndPop',
            animationspeed: 300,
            closeonbackgroundclick: false,
            dismissmodalclass: 'close'
        };

        var options = $.extend({}, defaults, options);
        var altezza = $(window).height();
        altezza = altezza * 0.5;

        return this.each(function() {

            var modal = $(this),
            modalheight = modal.height() * 0.8;
            topMeasure = parseInt(modal.css('top')),
            topOffset = modal.height() + topMeasure,
            locked = false,
            modalBG = $('.reveal-modal-bg');

            if (modalBG.length == 0) {
                modalBG = $('<div class="reveal-modal-bg" />').insertAfter(modal);
            }

            modal.bind('reveal:open', function() {
                modalBG.unbind('click.modalEvent');
                $('.' + options.dismissmodalclass).unbind('click.modalEvent');
                if (!locked) {
                    lockModal();

                    //modal.css({'opacity' : 0, 'visibility' : 'visible', 'top': $(window).scrollTop()+topMeasure});
                    modal.css({
                        'opacity': 0,
                        'visibility': 'visible',
                        'top': $(window).scrollTop() + altezza - modalheight
                    });
                    $('body').css('overflow-y', 'hidden')
                        modalBG.fadeIn(options.animationspeed / 2);
                    modal.delay(options.animationspeed / 2).animate({
                        "opacity": 1
                    }, options.animationspeed, unlockModal());

                }
                modal.unbind('reveal:open');

                $('.warning').hide();
                $('.loading').hide();
                $('.loadingoff').show();
                $('.reveal-modal').addClass('background');

            });

            modal.bind('reveal:close', function() {

                if (!locked) {
                    lockModal();

                    modalBG.delay(options.animationspeed).fadeOut(options.animationspeed);
                    modal.animate({
                        "opacity": 0
                    }, options.animationspeed, function() {
                        modal.css({
                            'opacity': 1,
                            'visibility': 'hidden',
                            'top': topMeasure
                        });
                        $('body').css('overflow-y', 'auto')
                            unlockModal();
                    });

                }

                modal.unbind('reveal:close');

            });

            modal.trigger('reveal:open')

                var closeButton = $('.' + options.dismissmodalclass).bind('click.modalEvent', function() {
                modal.trigger('reveal:close')
                });

            /*
                            if(options.closeonbackgroundclick) {
                                    modalBG.css({"cursor":"pointer"})
                                    modalBG.bind('click.modalEvent', function () {
                                      modal.trigger('reveal:close')
                                    });
                            }
                            $('body').keyup(function(e) {
                            if(e.which===27){ modal.trigger('reveal:close'); }
                            });
                            */

            function unlockModal() {
                locked = false;
            }
            function lockModal() {
                locked = true;
            }

        });

    }
    // $.fn.reveal
    $(".accetta").click(function() {

        var dati = new Object();
        dati = $("#listaCarte").val();

        var imageUrl = '';
        var x = ($('.reveal-modal').height());
        $('.loadingoff').hide();
        $('.loading').css('height', x).show();
        $('.reveal-modal').removeClass('background');

        $('<input>').attr({
            type: 'hidden',
            id: 'linkDaSostituire',
            name: 'linkDaSostituire',
            value: linkCorretto,
            });

        setTimeout(function() {
            $.ajax({

                type: "POST",
                url: "/portalppay/ScontiServlet",
                data: {
                    "linkDaSostituire": linkCorretto,
                    "cartaSelezionata": dati
                },
                dataType: "html",

                success: function(msg) {
                    //window.location = msg;
                    authWindow = window.open('about:blank');
                    authWindow.location.replace(msg);
                    //window.open(msg);
                    //var win=window.location(msg, '_blank');
                    //win.focus();
                    $('.reveal-modal').trigger('reveal:close');
                },

                error: function() {
                    $('.loadingoff').hide();
                    $('.loading').hide();
                    $('.warning').css('height', x - 40).show();
                }

            });
        }, 400);

    });
    // .accetta
    });

当我触发 ajax 调用时,使用以下代码块:

url: "/portalppay/ScontiServlet", 

我得到一个答案的 url,我确实在浏览器中看到了以下代码:

authWindow = window.open('about:blank');
authWindow.location.replace(msg);

问题是我无法在新选项卡中呈现链接,但总是在新的弹出窗口中!有人可以帮我解决问题吗?

4

1 回答 1

0

你检查过你的浏览器设置吗?

它是选择如何打开新窗口的浏览器。

在 Firefox 中,有一个在新选项卡中打开新窗口的选项,它告诉浏览器是否必须在新选项卡或...新窗口中打开新窗口。

在此处输入图像描述

请注意,仅当您在window.open 没有参数的情况下调用时才有效strWindowFeatures,指定它会强制浏览器(好吧,至少 Firefox 和 Explorer,Chrome 似乎没有类似的选项)在新窗口中打开链接。

欲了解更多信息:https ://developer.mozilla.org/en-US/docs/Web/API/window.open

于 2013-09-23T16:26:24.240 回答