2

I was writting a Ubiquity command but I have 0 expriece on JS. How to open an url (http://www.stackoverflow.com for example ) using JS?

EDIT:

Thanks you all, I believe you are correct, but with following code I was not be able to jump to so. It might be something related with Ubiquity but It was declared to be JS.

CmdUtils.CreateCommand({
names: ["so"],
preview: "go to stackoverflow",

execute: function so_execute() {
     displayMessage("Hello, World!");
     window.open('http://www.stackoverflow.com', 'dialog');
    //neither other two method will work
}
});
pierrotlefou
  • 39,805
  • 37
  • 135
  • 175

3 Answers3

6

1st method:

document.location.href = 'http://www.stackoverflow.com';

2nd method:

window.location = 'http://www.stackoverflow.com';

3rd method: (for new window/popup)

window.open('http://www.stackoverflow.com', 'dialog');
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
1

The following opens the given address in the current window.

 window.location = "http://www.stackoverflow.com";
aubreyrhodes
  • 777
  • 4
  • 16
1

(sorry for my english in advance)

I belive you're missing Utils.openUrlInBrowser(URL-TO-OPEN) or similar.

let me show you this code, open a new tab, with some content.


CmdUtils.CreateCommand({
  name: "bofh",
  preview: "Open a new tab with an BOFH excuse from The Bastard Operator From Hell-style excuse server..",
  execute: function(){
    Utils.openUrlInBrowser( "http://pages.cs.wisc.edu/~ballard/bofh/bofhserver.pl" );
  }
})

HTH

jfunez
  • 397
  • 6
  • 23