In SAS/HTML/javascript, how do you close a STP _webout html page immediately after it opens?

671 Views Asked by At

From a form in a web page, I'm opening a stored process (STP) in a new window.

<form target="_blank" action="http://<UrlToMySTP>" method="get" enctype="multipart/form-data">

that STP does someting and when it's done I need to close it's window. So I tried to close it with javascript like this

data _null_;
    file _webout;
    put '<HTML>';
    put '   <HEAD>';
    put '   </HEAD>';
    put '   <BODY onLoad="window.close()">';
    put '   </BODY>';
    put '</HTML>';
    run;

but I get an error message that says:

Scripts may close only the windows that were opened by it

I cannot find any solution for this. Is is possible to circumvent the problem to get to the same result ?

1

There are 1 best solutions below

7
On

You can try ajax query with dataType: "jsonp". Its can overcome CORS. STP must return json response, wrapped by name of js function, that wiil be executed in browser after ajax response.

Example

json_test.sas

 data _null_;
 file _WEBOUT;
 put "JSFunctionToAlertHTML({""Code"":0});";
 run;

html_test.html

Must contain:

$.ajax({
          url: "http://servername:port/SASStoredProcess/do?_program=path%2Fjson_test&callback=?",
          dataType: "jsonp"
        });

Make your attention to additional param callback=in url .

And

  function JSFunctionToAlertHTML(json){
    //Your code
  }

You also if you use EG to cretae stored process, you must exclude Stored Process macros from STP settings and set result capabilities to Stream.