views:

84

answers:

4

Hello everybody.

I have been building widget that accept user input and then once everything checked it will redirect user to the original web site.

However the best I achieved for now is that redirect will be opened in parent window rather then in new window.

Right now I am using

$(parent.location).attr('href', asoRequestURL);

However I would like to open redirected page in new window rather then in parent windows.

Is it possible ? And if yes then can you give me example.

Thanks in advance

+1  A: 

To open a new window in Javascript:

window.open('http://example.com');

Pop-up blockers, however, may refuse to open the window, so be prepared.

Matchu
+1  A: 

Is there some horrible problem with window.open(asoRequestURL);? I know it's not technically jQuery, but so far as I can tell it would take a plugin to be able to do. Is it really worth downloading a plugin to replicate such simple functionality?

EDIT: Here is all the information you could ever want on window.open(); it may not be ultraclean jQuery smooth, but this isn't really what jQuery is meant for.

Here is a function to make it ultra-cool-smooth using objects for parameters and such:

function openWin(url, name, params) {
    if (params != undefined && typeof params == 'object') {
        var paramStr = '';
        for (var p in params) {
            paramStr += p + '=' + params[p] + ',';
        }
        paramStr = paramStr.substr(0, paramStr.length - 1);
        window.open(url,name,paramStr);
    }
    else {
        window.open(url,name);
    }
}

And use it like:

openWin('http://blah-blah/', 'myWin', {width: 400, height: 400, menubar: 'no'});
Dereleased
That's exactly what I was looking for.Thanks a lot.
Dmitris
+1  A: 

If you want to modify the parent URL...

 parent.location.href = 'http://www.example.com/';

If you want to open in a new window...

 window.open('http://www.example.com/', 'nameWithoutSpaces', '{features}');
scunliffe
A: 

What about doing it in a hyperlink and controlling the behavior of the hyperlink (if it can be clicked or not) via javascript.

<a href='http:://example.com' target='_blank'>example</a>
Dan Littlejohn
Unfortunately I just need to generate URL from user input and Google map api and redirect the user to new window.
Dmitris