第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

怎么設(shè)置JQuery事件時(shí)繞過(guò)窗口上的彈出阻止程序。

怎么設(shè)置JQuery事件時(shí)繞過(guò)窗口上的彈出阻止程序。

慕斯王 2019-10-20 16:12:27
設(shè)置JQuery事件時(shí)繞過(guò)窗口上的彈出阻止程序。我想在超鏈接的單擊事件上有條件地顯示一個(gè)JQuery對(duì)話框。我有一個(gè)類(lèi)似于onCondition1的要求,打開(kāi)一個(gè)JQuery對(duì)話,如果條件1不滿足,導(dǎo)航到由其單擊事件的‘href’標(biāo)記引用的頁(yè)面。我能夠在鏈接的點(diǎn)擊事件上調(diào)用一個(gè)函數(shù)。這個(gè)函數(shù)現(xiàn)在通過(guò)執(zhí)行另一個(gè)URL(執(zhí)行我的Spring控制器并返回響應(yīng))來(lái)檢查上述條件。所有操作都很完美,只有窗口。打開(kāi)被彈出窗口阻止。$('a[href*=/viewpage?number]').live('click', function(e) {     e.preventDefault();     redirectionURL = this.href;     pageId= getUrlVars(redirectionURL)["number"];     $.getJSON("redirect/" + pageId, {}, function(status) {         if (status == null) {             alert("Error in verifying the status.");         } else if(!status) {             $("#agreement").dialog("open");         } else {             window.open(redirectionURL);         }     });});如果我把e.preventDefault();從代碼中,popoup阻止程序不會(huì)阻塞頁(yè)面,但是對(duì)于條件1,它會(huì)打開(kāi)對(duì)話并打開(kāi)‘href’頁(yè)面。如果我解決了一個(gè)問(wèn)題,就會(huì)給另一個(gè)人制造問(wèn)題。我不能同時(shí)公正地對(duì)待這兩種情況。你能幫我解決這個(gè)問(wèn)題嗎?一旦這個(gè)問(wèn)題解決了,我還有另一個(gè)問(wèn)題要解決,那就是在對(duì)話的OK事件上導(dǎo)航:)
查看完整描述

3 回答

?
智慧大石

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊

彈出阻止程序通常只允許window.open如果使用期間用戶事件的處理(如單擊)。在你的情況下,你打電話給window.open 后來(lái),而不是在活動(dòng)期間,因?yàn)?/trans>$.getJSON是異步的。

你有兩個(gè)選擇:

  1. 做點(diǎn)別的事,而不是window.open.

  2. 讓Ajax調(diào)用是同步的,這是您通常應(yīng)該避免的事情,因?yàn)樗i定了瀏覽器的UI。$.getJSON相當(dāng)于:

    $.ajax({
      url: url,
      dataType: 'json',
      data: data,
      success: callback});

    .這樣你就可以$.getJSON通過(guò)將Params映射到上面并添加async: false:

    $.ajax({
        url:      "redirect/" + pageId,
        async:    false,
        dataType: "json",
        data:     {},
        success:  function(status) {
            if (status == null) {
                alert("Error in verifying the status.");
            } else if(!status) {
                $("#agreement").dialog("open");
            } else {
                window.open(redirectionURL);
            }
        }});

    同樣,如果您能夠找到實(shí)現(xiàn)目標(biāo)的其他方法,我也不提倡同步Ajax調(diào)用。但如果你做不到,那就去吧。

    下面是由于異步調(diào)用導(dǎo)致測(cè)試失敗的代碼示例:

(由于對(duì)JSBin的更改,活動(dòng)鏈接不再工作)

jQuery(function($) {
  // This version doesn't work, because the window.open is
  // not during the event processing
  $("#theButton").click(function(e) {
    e.preventDefault();
    $.getJSON("http://jsbin.com/uriyip", function() {
      window.open("http://jsbin.com/ubiqev");
    });
  });});

下面是一個(gè)實(shí)際工作的例子,使用同步調(diào)用:

(由于對(duì)JSBin的更改,活動(dòng)鏈接不再工作)

jQuery(function($) {
  // This version does work, because the window.open is
  // during the event processing. But it uses a synchronous
  // ajax call, locking up the browser UI while the call is
  // in progress.
  $("#theButton").click(function(e) {
    e.preventDefault();
    $.ajax({
      url:      "http://jsbin.com/uriyip",
      async:    false,
      dataType: "json",
      success:  function() {
        window.open("http://jsbin.com/ubiqev");
      }
    });
  });});



查看完整回答
反對(duì) 回復(fù) 2019-10-21
?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

我有這個(gè)問(wèn)題,我還沒(méi)有準(zhǔn)備好我的url,直到回調(diào)會(huì)返回一些數(shù)據(jù)。解決方案是在啟動(dòng)回調(diào)之前打開(kāi)空白窗口,然后在回調(diào)返回時(shí)設(shè)置位置。

$scope.testCode = function () {
    var newWin = $window.open('', '_blank');
    service.testCode().then(function (data) {
        $scope.testing = true;
        newWin.location = '/Tests/' + data.url.replace(/["]/g, "");
    });};



查看完整回答
反對(duì) 回復(fù) 2019-10-21
  • 3 回答
  • 0 關(guān)注
  • 514 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)