Search code examples
javascriptxmlhttprequestxdr

How to send HTTP requests without opening up windows in Javascript?


Now I'm trying to open a series of URLs with window.open

for(i=0;i<10;i++)
{
    window.open("myapp://arg1/arg2/arg3/number_"+i);
}

It works fine except popping up ten windows.And I wonder if there's any way to do this work with windows not shown? Help would be appreciated!


Solution

  • If all you want to do is send those requests and you don't care about their response, you could create an Image:

    for(i=0;i<10;i++)
    {
        new Image().src = "myapp://arg1/arg2/arg3/number_"+i;
    }
    

    AFAIR, all the browsers I've tried that in (didn't test IE) downloaded the resource and didn't require me to actually display the image or append it to the DOM or anything. This is good for logging and prefetching stuff, but not much else.