admin管理员组

文章数量:1318328

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!

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!

Share Improve this question edited Dec 7, 2010 at 5:00 Josh Davis 28.7k5 gold badges54 silver badges67 bronze badges asked Dec 7, 2010 at 1:37 YoungYoung 8,3667 gold badges45 silver badges65 bronze badges 5
  • 2 What do you mean, "without popping up windows?" – Matt Ball Commented Dec 7, 2010 at 1:39
  • Do you need to display the contents, if your going a HTTP get only, why not make an AJAX call, or jquery get ie :: ` $.get('ajax/test.html', function(data) { $('.result').html(data); alert('Load was performed.'); });` – Jason Jong Commented Dec 7, 2010 at 1:40
  • @Matt Ball,I mean not open new web browser tab. – Young Commented Dec 7, 2010 at 1:43
  • 1 But then, what do you do with the response? If you only want to send a request and don't care about the response, see my answer. You should probably describe what you really want to acplish though, because you might be ing up with a solution to the wrong problem. – Josh Davis Commented Dec 7, 2010 at 1:45
  • @Jason Jong,Josh Davis,I need only a request to pass some arguments to my application. – Young Commented Dec 7, 2010 at 1:47
Add a ment  | 

3 Answers 3

Reset to default 6

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.

No. Not at all. You are calling window.open() 10 times in a loop.

You may want a JavaScript modal window.

Is there a way to do this without new windows being shown?

Sure:

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

Seriously though, you need to explain what it is that you expect to happen - the purpose of window.open is to open new (popup) windows, and if thats not what you want then you need another function.

Update: Having read your ment it appears that what you wish to do is send a HTTP request to that page (rather than open that page in a new window). The normal way to do this is to use the XMLHttpRequest object to send the request.

If you are using a JavaScript framework / library (such as jQuery) you will probably find that this object is wrapped in easier-to-use functions.

本文标签: xmlhttprequestHow to send HTTP requests without opening up windows in JavascriptStack Overflow