3

I have this JS method:

function OpenLink(strDestination)
{
    var features = ['left=10',
                    'top=10',
                    'location=0',
                    'menubar=0',
                    'resizable=0',
                    'scrollbars=1',
                    'status=0',
                    'titlebar=0',
                    'toolbar=0',
                    'width=' + (GetWinDimensions().Width - 500),
                    'height=' + (GetWinDimensions().Height - 150)];

    window.open(strDestination, "a", features.join(','));
}

Which opens a new browser window that does not have the address bar, navigation bar, or any other 'features'.

I have reviewed the MDN article pertinent to window.open. It says Internet Explorer and Firefox support the toolbar feature however it only worked in Firefox for me. The popup did not include the navigation buttons in IE, and as expected Chrome didn't either.

If I set all of these features to 1, then it was just opening a new tab. I tried changing the "a" string to "_blank" but it still opened a new tab rather than a new window.

How can I open a new window which also has the navigation bar enabled?

sab669
  • 3,984
  • 8
  • 38
  • 75

3 Answers3

2

You can do this:

function OpenLink(strDestination)
{
   var features = ['left=10',
                'top=10',
                'location=0',
                'menubar=0',
                'resizable=0',
                'scrollbars=1',
                'status=0',
                'titlebar=0',
                'toolbar=0',
                'width=' + window.innerWidth - 500,
                'height=' + window.innerHeight - 150];

   window.open(strDestination, "a", features.join(','));
}
Farzin Kanzi
  • 3,380
  • 2
  • 21
  • 23
  • 2
    This does not include the navigation menu in Chrome. Also you have extra `)` on your `width` and `height` values – sab669 May 05 '17 at 19:56
  • I removed the `)` , And have no idea about chrome. – Farzin Kanzi May 05 '17 at 19:57
  • Excellent, thank you! :) What is the purpose of "a"? – balazs630 Nov 27 '17 at 15:26
  • @balazs630 Thanks. "a" is an optional name for window that specifies the target attribute or the name of the window. To better understanding please see this: https://stackoverflow.com/questions/2438304/what-is-name-parameter-in-window-open – Farzin Kanzi Nov 28 '17 at 16:55
  • The problem is it doesn't seem Chrome can open a new set-size browser window *and* also include the navigation. – evolross Aug 30 '22 at 17:21
0

This simple code open a new window with navigation enabled and with 200 width , 100 height:

function myFunction() {
     var myWindow = window.open("", "", "width=200,height=100");
}
Mehdi Karimi
  • 528
  • 4
  • 25
  • 1
    This also does not include the navigation menu in Chrome. – sab669 May 05 '17 at 19:57
  • @sab669 what if you open a new tab instead of window? – Mehdi Karimi May 05 '17 at 20:09
  • It's strongly preferred that we open up a window as our users aren't typically "tech savy". Don't want to risk them closing the browser window (and therefore both tabs) when they mean to only close this popup. – sab669 May 05 '17 at 20:17
  • i didn't understand you first with browser navigation, then i found out what do you mean, so i will share if i find your solution ♥ – Mehdi Karimi May 05 '17 at 20:21
  • The problem is it doesn't seem Chrome can open a new set-size browser window *and* also include the navigation. – evolross Aug 30 '22 at 17:21
-1

You know and should know that mobile devices support new tab of different kinds and rarely windows at all if it is not available in progressive app technology like A2HS Adding event handlers to the window would solve the desktop problems with exiting . Just choose the right opening options. Thanks!