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
Avatar of lil_puffball
lil_puffball
Flag of Canada image

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)
Avatar of third
third
Flag of Philippines image

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.
Avatar of Zvonko
Zvonko
Flag of North Macedonia image



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.


Avatar of beneboop
beneboop

ASKER

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
Avatar of third
third
Flag of Philippines image

post your mainMenuItem function here.
Avatar of lil_puffball
lil_puffball
Flag of Canada image

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);
}
Avatar of third
third
Flag of Philippines image

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>
Avatar of beneboop
beneboop

ASKER

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
Avatar of lil_puffball
lil_puffball
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of beneboop
beneboop

ASKER

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!!!

Avatar of lil_puffball
lil_puffball
Flag of Canada image

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/questions/20936466/Points-for-third.html
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo