2

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!

Josh Davis
  • 28,400
  • 5
  • 52
  • 67
Young
  • 7,986
  • 7
  • 43
  • 64
  • 2
    What do you mean, _"without popping up windows?"_ – Matt Ball Dec 07 '10 at 01: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 Dec 07 '10 at 01:40
  • @Matt Ball,I mean not open new web browser tab. – Young Dec 07 '10 at 01: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 accomplish though, because you might be coming up with a solution to the wrong problem. – Josh Davis Dec 07 '10 at 01:45
  • @Jason Jong,Josh Davis,I need only a request to pass some arguments to my application. – Young Dec 07 '10 at 01:47

3 Answers3

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.

Josh Davis
  • 28,400
  • 5
  • 52
  • 67
1

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

You may want a JavaScript modal window.

alex
  • 479,566
  • 201
  • 878
  • 984
1

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 comment 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.

Justin
  • 84,773
  • 49
  • 224
  • 367