We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

open a new window in js drop down menu

beneboop
beneboop asked
on
Medium Priority
999 Views
Last Modified: 2007-12-19
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
Comment
Watch Question

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)

Commented:
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.
ZvonkoSystems architect
CERTIFIED EXPERT
Top Expert 2006

Commented:


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.


Author

Commented:
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

Commented:
post your mainMenuItem function here.
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);
}

Commented:
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>

Author

Commented:
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
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

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

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
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.