prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.54k stars 640 forks source link

Synchronous AJAX call in Safari doesn't allow window.open #211

Closed jwestbrook closed 9 years ago

jwestbrook commented 10 years ago

previous lighthouse ticket #26 by icfantv


Unless I'm missing something obvious, it appears that while a synchronous AJAX call in Safari via the Prototype library appears to be synchronous, it doesn't allow window.open to open a new window.

As the attached file will show, not using the prototype library, but rather a synchronous instance of the request.open(...) method on an XMLHttpRequest object does, in fact work, which leads me to believe it's an issue with Prototype and not Safari.

We've tested this with Prototype 1.6.0 and 1.6.0.2 and on Safari 3.1.1 and 3.0.4.

While I didn't comment the attached example, I believe it to be self explanatory. That said, please do not hesitate to email me if you have any issues or need me to test something.

Thanks,

--adam

jwestbrook commented 10 years ago

Tobie Langel April 18th, 2008 @ 03:17 PM

Could you kindly provide a simple failing test case (i.e. without all of the alerts) ? Thank you.

jwestbrook commented 10 years ago

icfantv April 18th, 2008 @ 03:28 PM

Of course, sorry about that. I only added those alerts to prove to myself that the call was indeed synchronous and wouldn't trigger a browser's security model's pop-up blocker. See attached for the same file w/o all the alerts. Thanks, --adam

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en">
  <head>
    <script language="javascript" type="text/javascript" src="prototype.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Test Page</title>
  </head>
  <body>
    <input type="button" value="popup doesn't work" onclick="handleClick();"/>
    <br/>
    <input type="button" value="popup works" onclick="handleAnotherClick();"/>
  </body>
  <script language="javascript" type="text/javascript">
    <!--

      var url = "http://www.cnn.com";
      var options = {
        asynchronous: false,
        method: 'get',
        parameters: '',

        onSuccess: function(t) {
          var testwin = window.open('http://www.google.com','testwin','width=750, height=700'); 
        },

        onFailure: function(t) {
          alert("failure!");
        }
      };

      function handleClick() {
        new Ajax.Request(url, options);
      }

      function handleAnotherClick() {

        var req = getAjaxRequestObject();
        if (req != null) {

          req.open("get", url, false);
          req.send(null);
          if (req.status == 200) {
            var testwin = window.open('http://www.google.com','testwin','width=750, height=700'); 
            if (testwin != null) {
              testwin.focus();
            }
          }
          else {
            alert("another failure!");
          }
        }
      }

      function getAjaxRequestObject() {

        var request = null;

        if (window.XMLHttpRequest) {
          request = new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
          request = new ActiveXObject("Microsoft.XMLHTTP");
        }

        return request;
      }

    //-->
  </script>
</html>
jwestbrook commented 10 years ago

Tobie Langel April 18th, 2008 @ 03:38 PM

This works for me. Tested on safari 3.0.4 with Prototype 1.6.0.2 on Mac OSX 10.4.11. Your issue is possibly related to violation of Same Origin Policy.

jwestbrook commented 10 years ago

ronin-15560 (at lighthouseapp) April 21st, 2008 @ 10:49 AM

IMHO, another reason to deprecate synchronous Ajax calls...

jwestbrook commented 10 years ago

Andrew Dupont October 4th, 2008 @ 05:18 AM

Closing for lack of test cases.

jwestbrook commented 10 years ago

icfantv October 4th, 2008 @ 07:30 AM

What do you mean "lack of test cases." If there's something I can do, aside from attaching files that give an example of the problem let me know.

jwestbrook commented 10 years ago

Andrew Dupont October 4th, 2008 @ 05:45 PM

Whoops! Sorry. I think I meant to close a different ticket instead. Does this happen only on localhost, or on remote servers as well?

jwestbrook commented 10 years ago

icfantv October 4th, 2008 @ 05:56 PM

As John David mentions above, he can reproduce on localhost but I'm pretty sure we tested it on a remote server and it doesn't work. It would be easier for me to re-test both cases on Monday at work and update the bug with the results.

jwestbrook commented 10 years ago

ronin-15560 (at lighthouseapp) October 5th, 2008 @ 11:14 AM

if you disable block popup windows in safari, it works fine. my vote is still for ditching support of synchronous ajax calls althogether. i've never seen a valid use case for this.

jwestbrook commented 10 years ago

Franco Monsalvo March 16th, 2010 @ 03:03 AM

Guys this is a really old bug, any chance you have already fixed it? Should I close it?

jwestbrook commented 10 years ago

icfantv March 16th, 2010 @ 05:40 AM

This bug is no longer blocking us as we've switched to jQuery but given the comments above - while I'm sure there is, I can't think of a case where a synchronous AJAX call, in any browser, would make sense. My vote is to close it but also to deprecate synchronous AJAX calls.

jwestbrook commented 10 years ago

Franco Monsalvo March 16th, 2010 @ 02:14 PM

Guys, any comment on this one?