Solved

open a new window in js drop down menu

Posted on 2004-03-28
11
950 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
0
Comment
Question by:beneboop
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10700736
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
 
LVL 30

Expert Comment

by:third
ID: 10700842
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 10700872


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
 

Author Comment

by:beneboop
ID: 10700881
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
 
LVL 30

Expert Comment

by:third
ID: 10700915
post your mainMenuItem function here.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:lil_puffball
ID: 10700920
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
 
LVL 30

Expert Comment

by:third
ID: 10700986
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
 

Author Comment

by:beneboop
ID: 10700998
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
 
LVL 12

Accepted Solution

by:
lil_puffball earned 125 total points
ID: 10701190
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
 

Author Comment

by:beneboop
ID: 10701340
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
 
LVL 12

Expert Comment

by:lil_puffball
ID: 10708219
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now