在新窗口中打开页面,没有弹出窗口阻止 [英] Open page in new window without popup blocking

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

问题描述

希望你能在这里帮忙...
我有一个表单翻译字段中的单词,用翻译的术语填充字段,然后在一个提交按钮中提交操作。

Hope you can help a bit here... I have a form that translate a word in a field, populate the field with the translated term and then do submit action all in one submit button.

提交由jquery提出。
问题是目标页面被阻止,因为所有3个主要浏览器都将其视为弹出窗口,
您是否知道如何将其作为新选项卡或新窗口打开?
我不想将目标设置为_self,因为我希望人们也可以打开我的网站。

the submit is being made by jquery. problem is the target page is being blocked as all 3 major browsers treat it as popup, Do you know how to let it open just as a new tab or new window ? I don't want to set the target as _self as I want people to have my site open as well.

我认为问题出现在这个字符串中:

I believe the problem is in this string:

document.forms.form1.submit();

但我也知道应该有一种方法来重新定义它,所以目标不会被视为一个弹出窗口。

but I also know there should be a way to rephrase it so the target won't be treated as a popup.

这是脚本:

<script type="text/javascript">

$(function transle() {
  $('#transbox').sundayMorningReset();
  $('#transbox input[type=button]').click(function(evt) {
    $.sundayMorning(
      $('#transbox input[type=text]').val(), {
        source: '',
        destination: 'ZH',
        menuLeft: evt.pageX,
        menuTop: evt.pageY
      },
      function(response) {
        $('#transbox input[type=text]').val(response.translation);

        //document.getElementById("form1").submit();
        document.forms.form1.submit();

      }
    );
  });
});

</script>

这是表格:

<table id="transbox" name="transbox" width="30px" border="0" cellspacing="0" cellpadding="0">
  <form action="custom-page" method="get" name="form1" target="_blank" id="form1">

    <tr>
      <td>
        <input id="q" name="q" type="text" class="search_input" onFocus="if (this.value == 'Evening dress') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Evening dress';}" value="Evening dress" />
      </td>
      <td>
        <input type="button" value="Find" style="color: #333; width: 157px; font-weight:bold"></input>
      </td>
    </tr>

  </form>
</table>

编辑

我已尝试提交所有这些字符串:

I have tried all of these strings to submit:

document.getElementById("form1").submit();
document.forms.form1.submit();
form1.submit();

所有目标都被弹出窗口阻止。
拜托,有没有其他方法我应该做代码不让它弹出?

all ends up with the target being popup blocked. please, is there any other way I should do the code to not let it popup ?

也许应该使用onsubmit来制作jQuery?
有人知道怎么做?

maybe should use the onsubmit to make jQuery ? someone knows how ?

推荐答案

浏览器只会在没有弹出窗口阻止程序警告的情况下打开标签/弹出窗口打开选项卡/弹出窗口来自可信任事件。这意味着用户必须主动点击某处以打开弹出窗口。

A browser will only open a tab/popup without the popup blocker warning if the command to open the tab/popup comes from a trusted event. That means the user has to actively click somewhere to open a popup.

在您的情况下,用户执行单击以便您拥有受信任的事件。但是,通过执行Ajax请求,您确实会丢失该可信上下文。您的成功处理程序不再具有该事件。避免这种情况的唯一方法是执行同步Ajax请求,该请求会在运行时阻止浏览器,但会保留事件上下文。

In your case, the user performs a click so you have the trusted event. You do lose that trusted context, however, by performing the Ajax request. Your success handler does not have that event anymore. The only way to circumvent this is to perform a synchronous Ajax request which will block your browser while it runs, but will preserve the event context.

在jQuery中,这应该是技巧:

In jQuery this should do the trick:

$.ajax({
 url: 'http://yourserver/',
 data: 'your image',
 success: function(){window.open(someUrl);},
 async: false
});

这是你的答案:在用户点击ajax调用后打开没有弹出窗口拦截器的新选项卡

这篇关于在新窗口中打开页面,没有弹出窗口阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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