views:

103

answers:

3

Hi,

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
}
});
+1  A: 

The following opens the given address in the current window.

 window.location = "http://www.stackoverflow.com";
aubreyrhodes
+6  A: 

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
+1  A: 

hi pierr (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

juanduke