Javascript - Window.open in a tab

DancingFighterG
DancingFighterG used Ask the Experts™
on
Hello,

I'm trying to a change to an old website that uses javascript to open up pages in pop-up boxes and change the functionality to op up the page on a new tab. Overall, I'm planning to move this entire website to a CMS system such as WP or Joomla but for now I'm going to fix this issue. Here is an example of the code that is being used to allow this to function with pop-ups:

Menu2=new Array("For the Employee","","",4,23,162);
	Menu2_1=new Array("Corporate HR","javascript:window.open('/hdintranet/divisionsites/corporate/redirectCorpHR.html','','toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,height=400,width=630,top=30,left=160,position=40')","",0,20,185);
	Menu2_2=new Array("Plastics & Die Casting Center HR","javascript:window.open('/hdintranet/divisionsites/manufacturing/owensboro/index.html','','toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,height=400,width=630,top=30,left=160,position=40')","",0,20,185);
	Menu2_3=new Array("Window Fashions Division","javascript:window.open('/hdintranet/divisionsites/manufacturing/wfd/index.html','','toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,height=400,width=630,top=30,left=160,position=40')","",0,20,185);
	Menu2_4=new Array("Information Center","","",3,20,150);
			Menu2_4_1 = new Array("Cell Phone Discounts","/hdintranet/foremployees/informationcenter/phonediscount.html","",0,20,150);
			Menu2_4_2 = new Array("Do Not Call Registry","/hdintranet/foremployees/informationcenter/phonedonotcall.html","",0,20,150);
			Menu2_4_3 = new Array("Hertz Rent2buy Discount","/hdintranet/foremployees/informationcenter/hertzdiscount.html","",0,20,150);

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
I believe it's up to the browser settings to tell the window to open in a new tab, but it might work just removing all the other arguments like this:

window.open('/hdintranet/divisionsites/corporate/redirectCorpHR.html');

Open in new window

Author

Commented:
Ok, I can take away the pop-up with no issues but I now need it to open up in a different table

Commented:
It's up to the browser after that.  You can force a popup, but not a tab.  Most browsers should default opening a '_blank' window to a new tab.
Ok, found some additional help on this and this is what we did:

In the function that is used to trigger the window open we did the following:

function winopen(url) {
            
            document.getElementById('pageLinks').href=url;
            document.getElementById('pageLinks').click();
      }

In the html that makes the menu we placed this code in:

<a href="#" target="_blank" id="pageLinks"></a>

From there I change the code in the js to look like this:

Menu2_1=new Array("Corporate HR", "javascript:winopen('/hdintranet/divisionsites/corporate/redirectCorpHR.html')","",0,20,185);

So we used the revised winopen function to open up the page in a new tab. So any link in the site will open up in the tab

Now I just have to update all the nav to use the function

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial