views:

540

answers:

3

It opens neither a tab nor a window: the code for a Google Gadget here. If you know 'target="_blank"' from HTML, I am looking for a similar tool for Google Gadgets. More precisely, I cannot understand why the JavaScript piece does not work:

window.open("http://www.google.com/");
+3  A: 

Well, if you want to open the new window, do it explicitly.

var query = "bijection";
var searchUrl = "http://www.google.com/search?q=";

if (query != "" && searchUrl != "") {
    searchUrl += escape(query);
    window.open(searchUrl); //You can pass additional parameters, look for window.open examples on the Internet.
    return false;
}

The target attribute is for link element () which instructs browser to open the URL in new window if user clicks on it.

SolutionYogi
What is then for this thing? Is it just open? But what is the parameter to open it in new tab?
Masi
Look at window.open examples here.http://www.javascript-coder.com/window-popup/javascript-window-open.phtmlAnd I don't think you can specify that new window should be opened in a tab.
SolutionYogi
+2  A: 

Open a new window with that target instead of replacing the current’s window URL:

var query = "bijection";
var searchUrl = "http://www.google.com/search?q=";
if (query != "" && searchUrl != "") {
    searchUrl += escape(query);
    var newWindow = window.open(searchUrl, '_blank');
    return false;
}
Gumbo
It looks promising. How did you get it working? I tried: http://code.google.com/apis/ajax/playground/, Google Gadget editor and even the navbar in my browser. Anything does not happen.
Masi
A: 

Like this?

searchUrl += escape(query);
thenewwindow=window.open(searchUrl,'Google','height=600,width=450');
return false;
redwall_hp