lkpetty Posted October 30, 2006 Posted October 30, 2006 Hi all,I'd like to launch external help documents from several of my infopath forms. It appears the only way I can do this would be through Javascript assigned to the button. Unfortunatly, I don't have a clue what the script might look like. We might want, for instance, a button to launch Word Document, perhaps at "C:\help files\helpfile1.doc". It might be a PDF that we want launched in Adobe, or an Excel file, or maybe even a JPEG. You get the idea.Any help would be greatly appreciated. I've searched high and low for script snippets for this sort of thing to no avail. Thanks much,Kent in Anchorage
gunsmokingman Posted October 30, 2006 Posted October 30, 2006 (edited) Try This Notes This "\"" Acts Like A Double Quote For Path And File Names That Have Spaces C:\\help files\\helpfile1.docThis is the If Exists Statementvar Act = new ActiveXObject("Wscript.Shell");var Fso = new ActiveXObject("Scripting.FileSystemObject");var File = ("C:\\help files\\helpfile1.doc"); if (Fso.FileExists(File)) {Act.Run("\""+File+"\"",1,true);} else { Act.Popup("Can not find this file" +'\n'+ File, 0,"Missing", 0 + 32 + 4096);} This is the Try and Catch Statementvar Act = new ActiveXObject("Wscript.Shell"); var File = ("C:\\help files\\helpfile1.doc"); try {Act.Run("\""+File+"\"",1,true);} catch(e){ Act.Popup("Can not find this file" +'\n'+ File, 0,"Missing", 0 + 32 + 4096);}I made this HTA with the above scripts . It has a text box for user input of the File Name. It has this directory for the Folder = ("C:\\helpfiles\\").Save As If_Try_Run_User_Input.hta<HTML><HEAD><TITLE> < If Try Run User Input ></TITLE> <HTA:APPLICATION applicationname="If_Try_UserInput" maximizebutton="No" minimizebutton="No" scroll="no" showintaskbar="yes" singleinstance="yes" Icon="%SystemRoot%\explorer.exe"> <STYLE type="text/css"> body { font:10.25pt; font-family:Verdana,Palatino Linotype,Ms Comic; color:#E3E3E3; font-weight:bold; Text-Align:Center; filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=0,StartColorStr='#91c3e1',endColorStr='#1c3870'); } .TextOnly1 { font:8.25pt; font-family:Verdana,Palatino Linotype,Ms Comic; color:#00709d; font-weight:Bold; text-align:Left; } .Button { font: 8.25pt; font-family: Verdana, Palatino Linotype; color:#E1E1E1; font-weight:bold; Text-Align:Center; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#91c3e1',endColorStr='#1c3870'); padding-top:1; padding-bottom:1; cursor:Hand; Height:17; width:99; border-left: 1px Transparent; border-right: 2px Transparent; border-top: 1px Transparent; border-Bottom: 2px Transparent; } .TextBackGround { font:8.25pt; font-family: Verdana, Palatino Linotype, Ms Comic; color:#1E1E1E; font-weight:bold; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#e2ded8',EndColorStr='#e8e2de;'); padding-top:1; padding-bottom:1; border-left: 3px Transparent; border-right: 2px Transparent; border-top: 3px Transparent; border-Bottom: 2px Transparent; } </STYLE> <script Language="JavaScript"> /* VARIBLES AND OBJECTS */ var Act = new ActiveXObject("Wscript.Shell"), Fso = new ActiveXObject("Scripting.FileSystemObject"); /* VARIBLES TITLE VARIBLE FOLDER VARIBLE FILE VARIBLE */ var Txt1=("If Try Run User Inputname Demo"), Folder = ("C:\\helpfiles\\"), File=(""); /* VARIBLES FONT TEXT DISDLAY */ var Font1=('<Font Style="font:10.75pt;color:#40766c;"><B> » </B></FONT>') /* ONLOAD EVENT */ function StartHta(){Text1.innerHTML = Txt1, window.resizeTo (405,175),window.moveTo (150,150);} /* IF_TRY_RUN_USERINPUT */ function If_Try_Run_UserInput(){if(Fso.FolderExists(Folder)){ try{Act.Run("\""+Folder+File+"\"",1,true);} catch(e){ alert("Can not find this file" +'\n'+ File);}}else{ alert("Can not find this folder" +'\n'+Folder);}} /* CHECK TO MAKE SURE THE TEXT BOX HAS VALUE */ function TextReply(){File=TextBox1.value if (File==""){ alert('No User Input Was Detected');}else{If_Try_Run_UserInput();}} /* CLEAR THE TEXTBOX OF TEXT */ function ClearTextbox1() {TextBox1.value="";} </SCRIPT></HEAD> <BODY Scroll='No' OnLoad='StartHta()'><TABLE><TD Height='24' VAlign='Top'> <SPAN ID='Text1' Class='TextOnly1'> </SPAN></TD></TABLE> <!-- ===== TEXTBOX START ===== --> <TABLE><script Language="JavaScript"> /* DISPLAY TEXT MESSAGE ONMOUSEOVER AND MOUSEOUT EVENT */ function TxtChange(){if(TextBox1.value =="") {(Text1.innerHTML='Type in the File Name you want to open?');}else{(Text1.innerHTML=Txt1);}} </SCRIPT> <INPUT Type=text Size=41 Class='TextBackGround' name=TextBox1 OnMouseOver='TxtChange()' OnMouseOut='TxtChange()'></TABLE> <!-- ===== TEXTBOX END ===== --> <TABLE><TD Class='TextBackGround' Height='21'> <!-- ===== BUTTON 01 START ===== --> <INPUT Type='Button' Class='Button' Name='Bttn1' Value='Open File' OnClick='TextReply()' OnMouseOver='this.style.color="#00cad4",Bttn1ChangeText()' OnMouseOut='this.style.color="#E1E1E1",Bttn1ChangeText()'> <script Language="JavaScript"> /* CHANGE TEXT ON BUTTON 01 AND TO DISPLAY A TEXT MESSAGE */ function Bttn1ChangeText(){if(Bttn1.value =="Open File") {Bttn1.value =('Press To Open'),(Text1.innerHTML='Opens the file in this Folder'+Font1+Folder);} else {Bttn1.value ='Open File',Text1.innerHTML=Txt1;}}</SCRIPT> <!-- ====== BUTTON 01 END ====== --> <!-- ===== BUTTON 02 START ===== --> <INPUT Type='Button' Class='Button' Name='Bttn2' Value='Clear Text' OnClick='ClearTextbox1()' OnMouseOver='this.style.color="#00cad4",Bttn2ChangeText()' OnMouseOut='this.style.color="#E1E1E1",Bttn2ChangeText()'> <script Language="JavaScript"> /* CHANGE TEXT ON BUTTON 02 */ function Bttn2ChangeText() {if(Bttn2.value =="Clear Text") {Bttn2.value =('Press To Clear'),(Text1.innerHTML='This will clear this text'+Font1+TextBox1.value);} else {Bttn2.value ='Clear Text',Text1.innerHTML=Txt1;}}</SCRIPT> <!-- ====== BUTTON 02 END ====== --> <!-- ===== BUTTON 03 START ===== --> <INPUT Type='Button' Class='Button' Name='Bttn3' Value='Close Hta' OnClick='window.close()' OnMouseOver='this.style.color="#00cad4",Bttn3ChangeText()' OnMouseOut='this.style.color="#E1E1E1",Bttn3ChangeText()'> <script Language="JavaScript"> /* CHANGE TEXT ON BUTTON 03 */ function Bttn3ChangeText(){if(Bttn3.value =="Close Hta") {Bttn3.value =('Press To Exit'),(Text1.innerHTML='Press to close this'+Font1+document.title);} else{Bttn3.value =('Close Hta'),(Text1.innerHTML=Txt1);}} </SCRIPT> <!-- ====== BUTTON 03 END ====== --> </TD></TABLE></BODY></HTML> Edited October 31, 2006 by gunsmokingman
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now