jakubdaniel
jakubdaniel

Reputation: 2223

Chrome JavaScript location object

I am trying to start 3 applications from a browser by use of custom protocol names associated with these applications. This might look familiar to other threads started on stackoverflow, I believe that they do not help in resolving this issue so please dont close this thread just yet, it needs a different approach than those suggested in other threads.

example:

ts3server://a.b.c?property1=value1&property2=value2
...
...

to start these applications I would do

location.href = ts3server://a.b.c?property1=value1&property2=value2
location.href = ...
location.href = ...

which would work in FF but not in Chrome

I figured that it might by optimizing the number of writes when there will be effectively only the last change present.

So i did this:

function a ()
{
  var apps = ['ts3server://...', 'anotherapp://...', '...'];

  b(apps);
}

function b (apps)
{
  if (apps.length == 0) return;

  location.href = apps[0]; alert(apps[0]);

  setTimeout(function (rest) {return function () {b(rest);};} (apps.slice(1)), 1);
}

But it didn't solve my problem (actually only the first location.href assignment is taken into account and even though the other calls happen long enough after the first one (thanks to changing the timeout delay to lets say 10000) the applications do not get started (the alerts are displayed).

If I try accessing each of the URIs separately the apps get started (first I call location.href = uri1 by clicking on one button, then I call location.href = uri2 by clicking again on another button).

Replacing:

location.href = ...

with:

var form = document.createElement('form');
form.action = ...
document.body.appendChild(form);
form.submit();

does not help either, nor does:

var frame = document.createElement('iframe');
frame.src = ...
document.body.appendChild(frame);

Is it possible to do what I am trying to do? How would it be done?

EDIT:

a reworded summary

i want to start MULTIPLE applications after one click on a link or a button like element. I want to achieve that with starting applications associated to custom protocols ... i would hold a list of links (in each link there is one protocol used) and i would try to do "location.src = link" for all items of the list. Which when used with 'for' does optimize to assigning only once (the last value) so i make the function something like recursive function with delay (which eliminates the optimization and really forces 3 distinct calls of location.src = list[head] when the list gets sliced before each call so that all the links are taken into account and they are assigned to the location.src. This all works just fine in Mozilla Firefox, but in google, after the first assignment the rest of the assignments lose effect (they are probably performed but dont trigger the associated application launch))

Upvotes: 3

Views: 786

Answers (1)

Lysol
Lysol

Reputation: 1547

Are you having trouble looping through the elements? if so try the for..in statement here

Or are you having trouble navigating? if so try window.location.assign(new_location);

[edit] You can also use window.location = "...";

[edit] Ok so I did some work, and here is what I got. in the example I open a random ace of spades link. which is a custom protocol. click here and then click on the "click me". The comments show where the JSFiddle debugger found errors.

Upvotes: 1

Related Questions