为什么我不能在我的jquery ajax回调打开一个新窗口? [英] Why can't I open a new window on my jquery ajax callback?

查看:107
本文介绍了为什么我不能在我的jquery ajax回调打开一个新窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在几个例子中显示我的问题...

to show my problem in a couple examples...

这个工作

$.post("SomePage.aspx", { name : "value" },
      function (data) {
         alert(data);
      }, "text");

这不起作用

$.post("SomePage.aspx", { name : "value" },
          function (data) {
             window.open("http://www.google.com");
          }, "text");

在第一个例子中,在第二个例子中,什么也没有发生。没有打开窗口。如果我在window.open调用之前或之后添加一个警报或某些事情,警报将正常工作,但窗口不会打开。如果我在$ .post方法之后完全添加一个window.open,那么窗口打开很好(当然这根本不能帮助我)。

In the first example, I get alerted with what i'm expecting. In the second example, nothing happens. No window is opened. If I add an alert or something before or after the window.open call, the alert works fine, but the window doesn't open. If I add a window.open completly after the $.post method, the window opens fine (of course this doens't help me at all).

想知道为什么我不能在回调中打开一个窗口。我要做什么才能打开一个窗口?我想打开一个窗口显示一些花哨的结果。

I'm wondering why I can't open a window in the callback. What do I have to do to be able to open a window? I'd like to open a window to show some fancy results.

任何帮助是感谢,谢谢。

Any help is appreciated, thanks.

推荐答案

应该工作?

尝试使用窗口名称?

window.open("http://www.google.com", "MyWindow");

http://www.javascript-coder.com/window-popup/ javascript-window-open.phtml


window.open方法
的语法如下:open (URL,
windowName [,windowFeatures])

The syntax of the window.open method is given below: open (URL, windowName[, windowFeatures])

第二个参数不是可选的javascript),也许在回调中没有它很奇怪的事情吗?

the 2nd parameter is not optional (of course, everything is optional in javascript), maybe something weird happens in the callback without it?

也可能是在新标签页或当前窗口后面打开?

also, possible it is opening in a new tab or behind the current window?

var x = window.open("http://www.google.com", "MyWindow");
x.focus();

这篇关于为什么我不能在我的jquery ajax回调打开一个新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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