Avatar of beneboop
beneboop asked on

open a new window in js drop down menu

I have a Website set up with javascript menus - and they work great.  I am now setting up an Intranet - and using the same js menuing - HOWEVER - since many of the links for the Intranet are linked directly to files (Word, Excel) - I need them to open in new windows, so the user gets their ussusal working environment when they open them. instead of the IE window.

Here's an example of my menus (I'm just leaving 1 drop down) - the first one is the original  

startMainMenu("tab_totalsupport_left.gif",25,8,2,2,0)
mainMenuItem("tab_totalsupport_b1",".gif",25,45,loc+"../survey.doc","","Survey",2,2,"tab_totalsupport_plain");
endMainMenu("tab_totalsupport_right.gif",25,8)

here is my try for a new window.. however I get an error: Expected ')' -- and the menu does not load...

startMainMenu("tab_totalsupport_left.gif",25,8,2,2,0)
mainMenuItem("tab_totalsupport_b1",".gif",25,45,javascript:window.open(loc+"../survey.doc"),"","Survey",2,2,"tab_totalsupport_plain");
endMainMenu("tab_totalsupport_right.gif",25,8)

I'd appreciate any help - thanks in advance for your time!!!!
Cindy
JavaScript

Avatar of undefined
Last Comment
lil_puffball

8/22/2022 - Mon
lil_puffball

You just need to surround it with quotes, like so:

startMainMenu("tab_totalsupport_left.gif",25,8,2,2,0)
mainMenuItem("tab_totalsupport_b1",".gif",25,45,"javascript:window.open(loc+'../survey.doc')","","Survey",2,2,"tab_totalsupport_plain");
endMainMenu("tab_totalsupport_right.gif",25,8)
third

i suggest you use the original,

startMainMenu("tab_totalsupport_left.gif",25,8,2,2,0)
mainMenuItem("tab_totalsupport_b1",".gif",25,45,loc+"../survey.doc","","Survey",2,2,"tab_totalsupport_plain");
endMainMenu("tab_totalsupport_right.gif",25,8)

then on your "mainMenuItem" function, look at the statement like

location.href = fifth_param_name;

or

location = fifth_param_name;

and change it to,

window.open(fifth_param_name,'docwin');


it would be better if you can post mainMenuItem function here.
Zvonko



Change your menues to open in named windows:

startMainMenu("tab_totalsupport_left.gif",25,8,2,2,0)
mainMenuItem("tab_totalsupport_b1",".gif",25,45,loc+"../survey.doc","Doc","Survey",2,2,"tab_totalsupport_plain");
endMainMenu("tab_totalsupport_right.gif",25,8)

The sixt parameter is the window name.
If you pass an empty string, then it is the same window.
In my example is the window name "Doc", but you can choose anything of your choice.
If you give two menu items the same window name, then they will both open in the same popup window.


I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
beneboop

lil puffball-
I tried your suggestion - it opened a new window - BUT it still opened it in the IE environment instead of opening in the Word environment...would I need another line to open the Word application first?
And... the original html window goes blanck with only the word [object] on it - so they still can't go back to the main menu?  any other ideas?

I am looking at thirds suggestion - but not sure I completely understand how to impliment the suggestion.

thanks again
third

post your mainMenuItem function here.
lil_puffball

I don't think it's possible to open it in another application, but you can fix the [object] part:

startMainMenu("tab_totalsupport_left.gif",25,8,2,2,0)
mainMenuItem("tab_totalsupport_b1",".gif",25,45,"javascript:openWin(loc+'../survey.doc')","","Survey",2,2,"tab_totalsupport_plain");
endMainMenu("tab_totalsupport_right.gif",25,8)

and put this in your script:

function openWin(url){
window.open(url);
}
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
third

you can but with the consequence of ActiveX,

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function openWord(doc){  
  word=new ActiveXObject("Word.Application")
  word.Documents.Open(doc)
  word.Visible = "true"
}
</script>
</head>
<body>
<a href="test.doc" onclick="openWord(this.href);return false;">Test</a>
</body>
</html>
ASKER
beneboop

Here is the main part of the menu...I used a menu generator to get the graphics and main menu tied together - from there I do the drop down menus manually.  When I tried Zvonko's suggestion to change the 6th param... I recieved an error messge about line 0 - "loc" is not defined????  That led me to look at the top generated section....  is that stopping me from getting Word to open in the new window??

if(typeof(loc)=="undefined"||loc==""){var loc="";if(document.body&&document.body.innerHTML){var tt=document.body.innerHTML.toLowerCase();var last=tt.indexOf("lec_intra_top.js\"");if(last>0){var first=tt.lastIndexOf("\"",last);if(first>0&&first<last)loc=document.body.innerHTML.substr(first+1,last-first-1);}}}

var bd=1
document.write("<style type=\"text/css\">");
document.write("\n<!--\n");
document.write(".lec_intra_top_menu {z-index:999;border-color:#000000;border-style:solid;border-width:"+bd+"px 0px "+bd+"px 0px;background-color:#495e71;position:absolute;left:0px;top:0px;visibility:hidden;}");
document.write(".lec_intra_top_plain, a.lec_intra_top_plain:link, a.lec_intra_top_plain:visited{text-align:left;background-color:#495e71;color:#ffffff;text-decoration:none;border-color:#000000;border-style:solid;border-width:0px "+bd+"px 0px "+bd+"px;padding:1px 0px 1px 0px;cursor:hand;display:block;font-size:10pt;font-family:Georgia, Times New Roman, Times, serif;font-weight:bold;}");
document.write("a.lec_intra_top_plain:hover, a.lec_intra_top_plain:active{background-color:#6c8ca7;color:#000000;text-decoration:none;border-color:#000000;border-style:solid;border-width:0px "+bd+"px 0px "+bd+"px;padding:1px 0px 1px 0px;cursor:hand;display:block;font-size:10pt;font-family:Georgia, Times New Roman, Times, serif;font-weight:bold;}");
document.write("a.lec_intra_top_l:link, a.lec_intra_top_l:visited{text-align:left;background:#495e71 url("+loc+"lec_intra_top_l.gif) no-repeat right;color:#ffffff;text-decoration:none;border-color:#000000;border-style:solid;border-width:0px "+bd+"px 0px "+bd+"px;padding:1px 0px 1px 0px;cursor:hand;display:block;font-size:10pt;font-family:Georgia, Times New Roman, Times, serif;font-weight:bold;}");
document.write("a.lec_intra_top_l:hover, a.lec_intra_top_l:active{background:#6c8ca7 url("+loc+"lec_intra_top_l2.gif) no-repeat right;color: #000000;text-decoration:none;border-color:#000000;border-style:solid;border-width:0px "+bd+"px 0px "+bd+"px;padding:1px 0px 1px 0px;cursor:hand;display:block;font-size:10pt;font-family:Georgia, Times New Roman, Times, serif;font-weight:bold;}");
document.write("\n-->\n");
document.write("</style>");

var fc=0x000000;
var bc=0x6c8ca7;
if(typeof(frames)=="undefined"){var frames=0;}


*********here is where I start editing**************

I am only testing with the first button...

startMainMenu("lec_intra_top_left.gif",31,2,2,0,0)
mainMenuItem("lec_intra_top_b1",".gif",31,66,"javascript:window.open(loc+'../survey.doc')","","Home",2,2,"lec_intra_top_plain");
mainMenuItem("lec_intra_top_b2",".gif",31,127,"javascript:;","","Administration",2,2,"lec_intra_top_plain");
mainMenuItem("lec_intra_top_b3",".gif",31,86,"javascript:;","","Deputies",2,2,"lec_intra_top_plain");
mainMenuItem("lec_intra_top_b4",".gif",31,81,"javascript:;","","Records",2,2,"lec_intra_top_plain");
mainMenuItem("lec_intra_top_b5",".gif",31,85,"javascript:;","","Dispatch",2,2,"lec_intra_top_plain");
mainMenuItem("lec_intra_top_b6",".gif",31,50,"javascript:;","","Jail",2,2,"lec_intra_top_plain");
mainMenuItem("lec_intra_top_b7",".gif",31,117,"javascript:;","","Investigators",2,2,"lec_intra_top_plain");
endMainMenu("lec_intra_top_right.gif",31,2)

thanks again - Cindy
ASKER CERTIFIED SOLUTION
lil_puffball

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
beneboop

Thanks Everyone....
lil puffball... your first function openWin worked to open a new window - and removed the [object] problem I was getting on the source page.

I tired this last code quick - it didn't work for me - but I'll play with it a little more and see if I can get it.  Where I'm at right now will do - that would be EXTRA!!!

again - thanks a ton!!!

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
lil_puffball

Thanks beneboop for the points and the A! :)

I think third deserves some points too since I just incorporated his ActiveX code into mine, so third go here to get your points:

https://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20936466.html