admin管理员组

文章数量:1332352

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 ? If yes then can you give me example?

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 ? If yes then can you give me example?

Share Improve this question edited Dec 22, 2022 at 23:47 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 29, 2010 at 20:53 Dmitri S.Dmitri S. 3,4485 gold badges37 silver badges41 bronze badges 1
  • This is not a proper usage of jQuery. Please don't do it. – Matchu Commented Jan 29, 2010 at 21:02
Add a ment  | 

4 Answers 4

Reset to default 3

If you want to modify the parent URL...

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

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

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

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'});

To open a new window in Javascript:

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

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

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.' target='_blank'>example</a>

本文标签: javascriptRedirect from iframe to the new windowStack Overflow