Use window.open():

<a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');">
  Share Page
</a>

This will create a link titled Share Page which opens the current url in a new window with a height of 570 and width of 520.

Answer from citruspi on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › met_win_open.asp
Window open() Method
More examples below. The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › open
Window: open() method - Web APIs | MDN
The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.
🌐
Javatpoint
javatpoint.com › javascript-window-open-method
JavaScript Window open method - javatpoint
JavaScript Window open method with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-window-open-window-close-method
Javascript Window Open() & Window Close() Method | GeeksforGeeks
August 1, 2024 - The Javascript Window.Open() method is used to open the web pages into a new window or a new tab.
🌐
JavaScript.info
javascript.info › tutorial › frames and windows
Popups and window methods
There is also a number of less supported browser-specific features, which are usually not used. Check window.open in MDN for examples.
🌐
Educative
educative.io › answers › what-is-the-windowopen-method-in-javascript
What is the window.open() method in JavaScript?
var fourthWindow = window.open("https://www.wikipedia.org", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
Find elsewhere
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript openwindow
JavaScript openWindow | How does openWindow() works in JavaScript?
April 15, 2023 - If, in case, we do not provide any URL, an empty window would be loaded (about:blank) with the default toolbars of the main window. Remote URLs won’t be loaded. The creation of the window and actual loading of the URL is deferred, and the script executes asynchronously. Given below are the examples of JavaScript openWindow:
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
TutorialsPoint
tutorialspoint.com › how-to-open-link-in-a-new-window-javascript
How to open link in a new window using JavaScript?
September 25, 2024 - <!DOCTYPE html> <html lang="en"> ... <body> <a href="https:///www.google.com" target="popup" onclick="window.open( 'https://www.tutorialspoint.com/javascript/index.htm','popup', 'width=500,height=500'); return false;"> JavaScript ...
🌐
EncodedNA
encodedna.com › 2013 › 09 › javascript-window-open-method.htm
Open a New Browser Window using JavaScript open() Method
Accepts values like 0 and 1 or yes and no to specify if the page of the newly opened window can be scrolled or not. Again, try different browsers to check the result. Check this feature after reducing the width and height of the window.
🌐
Tabnine
tabnine.com › home page › code › javascript › window
builtins.Window.open JavaScript and Node.js code examples | Tabnine
viewer.on('mouseenter', STR_SELECTOR, function(e) { if (!(e.ctrlKey || e.metaKey)) { return; } var elem = $(this); if (LINK_RE.test(elem.text())) { elem.addClass('w-is-link'); } }).on('mouseleave', STR_SELECTOR, function() { $(this).removeClass('w-is-link'); }).on('mousedown', STR_SELECTOR, function(e) { if (!(e.ctrlKey || e.metaKey)) { return; } var elem = $(this); if (LINK_RE.test(elem.text())) { window.open((RegExp.$1 || 'http:') + RegExp.$2); } });
🌐
Quackit
quackit.com › javascript › popup_windows.cfm
JavaScript Popup Windows
If you only want to open a new browser window you can add the target="_blank" attribute within the <a> element (see this article on opening a new window in HTML). JavaScript popup windows however, are more powerful. Using JavaScript's window.open() method, you can determine what the window ...
🌐
ThoughtCo
thoughtco.com › open-link-new-window-javascript-3468859
How to Create Links That Open in a New Window With JavaScript
April 14, 2020 - Here's how to open a link in a new window using JavaScript and how to customize its look with parameters.
🌐
Eduonix
eduonix.com › blog › web-programming-tutorials › learn-how-to-implement-pop-up-windows-in-javascript
Online Learning Courses in Web, Software & Mobile Development
Online learning courses on Web Development, Software Development, Wordpress, SEO, Mobile & App Development are available at Eduonix Learning Solutions
🌐
Experts Exchange
experts-exchange.com › questions › 23578727 › How-to-save-a-window-reference-from-a-javascript-window-open-function-into-the-session.html
Solved: How to save a window reference from a javascript window.open function into the session | Experts Exchange
July 19, 2008 - Like this: <script> window.name="myNewName"; </script> But the window.open() method for sure reuses a window, iframe or frame if the name is found in any window on the desktop from same browser brand.
🌐
To The New
tothenew.com › home › how to send a post request in window.open() function of javascript.
How to send a POST request in window.open() function of JavaScript. | TO THE NEW Blog
December 19, 2016 - Notice the name of the window (‘myWindow’) is same as the name given in form’s ‘target’ attribute. On submitting this form, javascript will open a new window and the output of the form will get rendered in that window.
Top answer
1 of 4
39

To avoid circular calls, you need to stash away the original window.open function in a variable.

A nice way (that doesn't pollute the global namespace) is to use a closure. Pass the original window.open function to an anonymous function as an argument (called open below). This anonymous function is a factory for your hook function. Your hook function is permanently bound to the original window.open function via the open argument:

window.open = function (open) {
    return function (url, name, features) {
        // set name if missing here
        name = name || "default_window_name";
        return open.call(window, url, name, features);
    };
}(window.open);
2 of 4
15

I know this reply is a little late, but I felt that a more general solution may be helpful for other people (trying to override other methods)

function wrap(object, method, wrapper){
    var fn = object[method];

    return object[method] = function(){
        return wrapper.apply(this, [fn.bind(this)].concat(
            Array.prototype.slice.call(arguments)));
    };
};

//You may want to 'unwrap' the method later 
//(setting the method back to the original)
function unwrap(object, method, orginalFn){
    object[method] = orginalFn;
};

//Any globally scoped function is considered a 'method' of the window object 
//(If you are in the browser)
wrap(window, "open", function(orginalFn){
    var originalParams = Array.prototype.slice.call(arguments, 1);
    console.log('open is being overridden');
    //Perform some logic
    //Call the original window.open with the original params
    orginalFn.apply(undefined, originalParams); 
});