Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 964
  • Last Modified:

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
0
beneboop
Asked:
beneboop
  • 4
  • 3
  • 3
  • +1
1 Solution
 
lil_puffballCommented:
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)
0
 
thirdCommented:
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.
0
 
ZvonkoSystems architectCommented:


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.


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
beneboopAuthor 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
0
 
thirdCommented:
post your mainMenuItem function here.
0
 
lil_puffballCommented:
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);
}
0
 
thirdCommented:
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>
0
 
beneboopAuthor 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
0
 
lil_puffballCommented:
Interesting idea, third! :)
Here is the code, based on third's idea, incorporated into the function I gave you before:

-------------------------------------------
function openWin(url){
  var ext=url.substring(url.lastIndexOf(".")+1);
  var obj;
  if(ext=="doc"){
    obj=new ActiveXObject("Word.Application");
    obj.Documents.Open(url);
    obj.Visible="true";
  }else if(ext=="xls"){
    obj=new ActiveXObject("Excel.Application");
    obj.Workbooks.Open(url);
    obj.Visible="true";
  }else if(ext="ppt"){
    obj=new ActiveXObject("PowerPoint.Application");
    obj.Presentations.Open(url);
    obj.Visible="true";
  }else{
    window.open(url);
  }
}
-------------------------------------------

And remember, you call it like this:
-------------------------------------------
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)
-------------------------------------------
0
 
beneboopAuthor 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!!!

0
 
lil_puffballCommented:
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:

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now