Rebel_no_1
asked on
How do I make the text in my .hta (.Html application) not selectable?
I have several span elements in an .HTA script and I would like to prevent the user from selecting any text. My script looks like:
<html>
<head>
<HTA:APPLICATION
ID="objScreen"
APPLICATIONNAME="Screen"
BORDER="none"
BORDERSTYLE="normal"
CAPTION="no"
ICON=""
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="no"
SCROLL="no"
VERSION="1.0"
CONTEXTMENU="no"
WINDOWSTATE="maximize"
INNERBORDER="no"/>
</head>
<SPAN
STYLE="
top: 203;
left: 572;
width: 42px;
height: 43px;
position: absolute;
z-index: 1;
background-image: url('Busy.gif');
visibility: show;">
</SPAN>
<SPAN
STYLE="
top: 263;
left: 572;
width: 42px;
height: 43px;
position: absolute;
z-index: 1;
background-image: url('Busy.gif');
visibility: show;">
</SPAN>
<SPAN
STYLE="
top: 323;
left: 572;
width: 42px;
height: 43px;
position: absolute;
z-index: 1;
background-image: url('Busy.gif');
visibility: show;">
</SPAN>
<SPAN
STYLE="
top: 383;
left: 572;
width: 20px;
height: 20px;
position: absolute;
z-index: 1;
background-image: url('Busy.gif');
visibility: show;">
</SPAN>
<SPAN
STYLE="
top: 443;
left: 572;
width: 42px;
height: 43px;
position: absolute;
z-index: 1;
background-image: url('Busy.gif');
visibility: show;">
</SPAN>
<SPAN
STYLE="
top: 503;
left: 572;
width: 42px;
height: 43px;
position: absolute;
z-index: 1;
background-image: url('Busy.gif');
visibility: show;">
</SPAN>
<SPAN
STYLE="
top: 563;
left: 572;
width: 42px;
height: 43px;
position: absolute;
z-index: 1;
background-image: url('Busy.gif');
visibility: show;">
</SPAN>
<Script Language="VBScript">
Sub Window_OnLoad
' Size and position main window
window.resizeTo 1366,768
window.moveTo 0,0
' Display current time
myClock.innerText = Now()
' Set up a timer event so we can update the screen periodically
iTimerID = window.setInterval("myVBSClock", 1000)
End Sub
Sub myVBSClock
' Update current time
myClock.innerText = Now()
' Refresh colors from status file
CheckStatusFile
End Sub
Function ComputerName()
' Get computername
Set wshShell = CreateObject("WScript.Shell")
ComputerName = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set wshShell = Nothing
End Function
Sub CheckStatusFile
' Constants for file I/O
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
' Name of status file
strStatusFile = "Status.txt"
' Create file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Make sure status file exists
If objFSO.FileExists(strStatusFile) Then
' Open it for reading
Set objStatusFile = objFSO.OpenTextFile(strStatusFile, ForReading, False, TriStateUseDefault)
' Read status file, slit lines into array elements
arrStatus = Split(objStatusFile.ReadAll, vbCrLf)
' Close file, release objects
objStatusFile.Close
Set objStatusFile = Nothing
Set objFSO = Nothing
' Process each line of the status file (skip blank lines)
For Each strStatus in arrStatus
If strStatus <> "" Then
' Split status line into array at comma
arrField = Split(strStatus, ",")
' Process lines based on first field on line (item name to update), and set item color to status file value
Select Case arrField(0)
Case "Security-Environment"
SecurityEnvironment.style.background = arrField(1)
Case "Help-Menu"
HelpMenu.style.background = arrField(1)
Case "Biometric-License"
BiometricLicense.style.background = arrField(1)
Case "Card-Printer"
CardPrinter.style.background = arrField(1)
Case "GPS-Device"
GPSDevice.style.background = arrField(1)
Case "Battery-Controller"
BatteryController.style.background = arrField(1)
Case "Biometric-Application"
BiometricApplication.style.background = arrField(1)
End Select
End If
Next
End If
End Sub
</SCRIPT>
<BODY
BACKGROUND="bgimageV3.jpg"
TOPMARGIN="10"
RIGHTMARGIN="10"
LEFTMARGIN="10"
BGCOLOR="#7e7e7e">
<SPAN
id="SecurityEnvironment"
style="
top: 200;
left: 47;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
background: grey;
border-color: #000000;
border-style: solid;
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
text-align: left;
color: white;
font-family: Arial;
font-size : 40;
visibility: show;">
SECURITY ENVIRONMENT
</SPAN>
<SPAN
id="HelpMenu"
style="
top: 260;
left: 47;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
background: grey;
border-color: #000000;
border-style: solid;
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
text-align: left;
color: white;
font-family: Arial;
font-size : 40;
visibility: show;">
HELP MENU
</SPAN>
<SPAN
id="BiometricLicense"
style="
top: 320;
left: 47;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
background: grey;
border-color: #000000;
border-style: solid;
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
text-align: left;
color: white;
font-family: Arial;
font-size : 40;
visibility: show;">
BIOMETRIC LICENSE
</SPAN>
<SPAN
id="CardPrinter"
style="
top: 380;
left: 47;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
background: grey;
border-color: #000000;
border-style: solid;
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
text-align: left;
color: white;
font-family: Arial;
font-size : 40;
visibility: show;">
CARD PRINTER
</SPAN>
<SPAN
id="GpsDevice"
style="
top: 440;
left: 47;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
background: grey;
border-color: #000000;
border-style: solid;
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
text-align: left;
color: white;
font-family: Arial;
font-size : 40;
visibility: show;">
GPS DEVICE
</SPAN>
<SPAN
id="BatteryController"
style="
top: 500;
left: 47;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
background: grey;
border-color: #000000;
border-style: solid;
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
text-align: left;
color: white;
font-family: Arial;
font-size : 40;
visibility: show;">
BATTERY CONTROLLER
</SPAN>
<SPAN
id="BiometricApplication"
style="
top: 560;
left: 47;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
background: grey;
border-color: #000000;
border-style: solid;
border-top-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-right-width: 1px;
text-align: left;
color: white;
font-family: Arial;
font-size : 40;
visibility: show;">
BIOMETRIC APPLICATION"
</SPAN>
<SPAN
style="
top: 650;
left: 50;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
text-align: left;
color: fa8b0f;
font-family: Arial;
font-size : 60;
visibility: show;">
<script type="text/javascript"> document.write(computername());</script>
</SPAN>
<SPAN
style="
top: 670;
left: 515;
width: 570px;
height: 40px;
position: absolute;
z-index: 1;
text-align: left;
color: white;
font-family: Arial;
font-face : Arial;
font-size : 25;
font-weight: bold;
visibility: show;">
<font color="white"><PRE ID=myClock></font>
</SPAN>
</BODY>
</HTML>
ASKER
Here is another piece of code which seems to be able to do this. I just don't know how to make it part of my script to test?
<!-- Paste this code into an external JavaScript file named: disableSelect.js -->
/* This script and many more are available free online at
The JavaScript Source :: http://www.javascriptsource.com
Created by: James Nisbet (morBandit) :: http://www.bandit.co.nz/ */
window.onload = function() {
document.onselectstart = function() {return false;} // ie
document.onmousedown = function() {return false;} // mozilla
}
/* You can attach the events to any element. In the following example
I'll disable selecting text in an element with the id 'content'. */
window.onload = function() {
var element = document.getElementById('content');
element.onselectstart = function () { return false; } // ie
element.onmousedown = function () { return false; } // mozilla
}
<!-- Paste this code into the HEAD section of your HTML document.
You may need to change the path of the file. -->
<script type="text/javascript" src="disableSelect.js"></script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is a handy trick to stop people from selecting text. I had to place it within it's own script tags for some reason but I'm sure this is due to a possible problem elsewhere in my code. I will clean things up later and as I gain new knowledge. Thank you Rob!
No problem. You already have <script> tags for your vbscript code, so you need a new set for javascript code. The entire snippet that I posted has its own tags for that reason.
Happy learning!
Happy learning!
ASKER
I see what you mean. I'm still learning but I'll get there eventually! Thanks.
ASKER
Open in new window