Saving Scroll Position in HTA files - scrollbar

i have a HTA application with a wide scroll bar and i want to save the position of scroll bar that user left the application ,any solution?

Create a file named scroll.js in the same folder as your HTA file, which will be used for stocking the scrollbar's position. Then insert following code in your HTA:
<script type="text/javascript">
window.onbeforeunload = function(){
var myfile = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile("scroll.js",2,true);
myfile.WriteLine("document.body.scrollLeft = '" + document.body.scrollLeft + "';");
myfile.WriteLine("document.body.scrollTop = '" + document.body.scrollTop + "';");
myfile.Close();
}
</script>
So that when you open the HTA it puts the scrollbar like the user left it, you need to insert this code right before the </body> tag:
<script type="text/javascript" src="scroll.js"></script>

Related

How to Run HTA in hidden mode

I have an HTA file which works perfectly well, but my problem is that i will like the HTA console to be hidden when the file runs.
Here is my code:
<script>
var myVar = setInterval(function(){ myTimer() }, 3000);
function myTimer() {
objShell=new ActiveXObject("WScript.Shell");
objShell.Run ('%windir%\\System32\\cmd.exe /c %temp%\\readme.txt', 0);window.close();
}
</script>
Without the timer, it runs hidden, but when i include the timer it shows the console.
Can someone help me fix this?
Thank you
You have some options; you can use windowstate="minimize" in you HTA attributes see https://technet.microsoft.com/en-us/library/ee176567.aspx for more info about the attributes.
The app will still be shown on the taskbar while it runs so you can set showintaskbar to no but then you will see the window minimized small in the corner of the screen.
You can use window.resizeTo(0,0); with WINDOWSTATE="normal" but there will be a flicker of the window before it changes size.
You can experiment with the options and see which one best suits your needs.
<HTML>
<HEAD>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="myApp"
WINDOWSTATE="normal"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
CAPTION="no"
SHOWINTASKBAR="no"
>
<script>
window.resizeTo(0,0);
var myVar = setInterval(function(){ myTimer() }, 3000);
function myTimer() {
objShell=new ActiveXObject("WScript.Shell");
objShell.Run ('%windir%\\System32\\cmd.exe /c %temp%\\readme.txt', 0);window.close();
}
</script>
</HEAD>
<BODY SCROLL="no">
</BODY>
</HTML>
If you're just opening a text file, why bother with the command prompt? Also, why is there an interval if the HTA just closes right after the file is opened? I think you should be able to just do the following, while also using the WINDOWSTATE property as suggested by Gordon:
objShell.Run("%temp%\\readme.txt", 0, true);
window.close();

I want to enable text box on image click in asp using java script

I want to enable text box on image click in asp using java script initially my text box is disable
As you have added no markup to your question so i am assuming an Image and writing an example of how to disable/enable with Javascript
<html>
<body>
// Image
<img src="\URL" onClick="EnableTxt()" />
<script>
// Javascript Function
function EnableTxt() {
document.getElementById( '<%=txtBox.ClientID%>' ).disabled = 'false';
}
</script>
</body>
</html>

Use Javascript to copy Text from Label

Label1 (asp.net control) is located inside Panel1 of my webpage and I have a button called bt. What is the Javascript to copy the Text from Label1 to the clipboard?
#artlung, I placed the below code just outside of my form but inside the body. The last line of code I placed inside Panel1 of my form. Anything wrong with this code because nothing happens when I click the Copy to Clipboard button.
<script language="JavaScript">
var clip = new ZeroClipboard.Client();
clip.addEventListener( 'mouseDown', function(client) {
// set text to copy here
clip.setText( document.getElementById('form1.Label1').value );
// alert("mouse down");
} );
clip.glue( 'd_clip_button' );
</script>
The next line of code is above the script tags but inside Panel1 in my form
<div id="d_clip_button">Copy To Clipboard</div>
I achieved this with javascript. I picked up on the fact that javascript was renaming the label from Label1 to MainContent_Label1. Then I also through debugging saw that what I wanted to grab from the variable was the innerText property. Problem Solved!
I also had the function test for an empty string and then return a confirmation alert to the user when they either copied successfully to the clipboard or when the label was empty with nothing to copy. This is all client-side.
<asp:Label ID="Label1" runat="server" Text="Copy This!!!"></asp:Label>
<script type="text/javascript">
function ClipBoardTest() {
var txt = document.getElementById('MainContent_Label1');
window.clipboardData.setData("Text", txt.innerText);
if(!txt){
alert("Nothing to Copy");
}
else {
alert("Copy to ClipBoard Successful!");
}
}
</script>
<input type="button" id='bt' onclick="ClipBoardTest();" value="Copy" />
Use the zeroclipboard library.
There is also a way to copy text from label without using any external libraries.
copyStrFunction = (copyStr) => {
const el = document.createElement('textarea'); // Create a <textarea> element
el.value = copyStr; // Set its value to the string that you want copied
el.setAttribute('readonly', ''); // Make it readonly to be tamper-proof
el.style.position = 'absolute';
el.style.left = '-9999px'; // Move outside the screen to make it invisible
document.body.appendChild(el); // Append the <textarea> element to the HTML document
el.select(); // Select the <textarea> content
document.execCommand('copy'); // Copy - only works as a result of a user action (e.g. click events)
document.body.removeChild(el); // Remove the <textarea> element
}
Call the copyStrFunction() onclick of any button and the string.
You can also modify the above function to find the label by Id and then copying the text from it.

Register OnMouseOver-Event from CodeBehind?

I wan't to register the OnMouseOver and OnMouseOut-Event for an Image from the Code behind, because I must different if the user is logged in or not.
Any ideas?
You can add an attribute to the object.
e.g.
Image img = new Image();
img.Attributes.Add("onmouseover", "myjavascriptfunction();");
To set the paramater based on the id of the object, using this:
Image img = new Image();
img.Attributes.Add("onmouseover", "myjavascriptfunction(" + img.ClientID + ");");
Using ck's example, you can achieve what you're trying to do using the ClientID property on your server control. Like this:
yourImage.Attributes.Add("onmouseover", "jsfunction(" + yourImage.ClientID + ");");
On solution would be to use a css class and jQuery:
<img id="generatedId" class="myHoverImage" />
javascript:
$("img.myHoverImage").mouseover ( function() {
// you can access the generated id:
alert ( this.id );
// --> your code goes here <-- \\
});

iframe designMode in firefox

I create iframe with designMode=on.
When I open web site in IE and move mouse cursor on iframe, the mouse cursor get changes into text-cursor (big letter I).
But when I open web site in Firefox, the corsur doesn't change and stays arrow-point cursor.
How to fix that?
<script language="javascript" type="text/javascript">
designer('content');
function designer(editor) {
var browser = navigator.userAgent.toLowerCase();
isIE = (browser.indexOf("msie") != -1);
document.writeln('<iframe id="' + editor + '" width="600px" height="600px"></iframe>');
var edit = document.getElementById(editor).contentWindow.document;
edit.designMode = "On";
if (!isIE) {
document.getElementById(content).contentDocument.designMode = "on";
}
}
</script>
Maybe this page will help?
Try CSS, that should switch the cursor for you.
iframe{cursor:crosshair} //all iframes on page
or
#content{cursor:crosshair} //just the element with the id "content"
Question? where is the variable content set in the call: document.getElementById(content).contentDocument.designMode = "on";
Do you mean editor as in: var edit = document.getElementById(editor).contentWindow.document;
Okay, I see your problem, link to http://devedge-temp.mozilla.org/viewsource/2003/midas/01/example2-index.html has the same issue and that's the Mozilla way.
Your line:
if (!isIE) {
document.getElementById(content).contentDocument.designMode = "on";
}
Should almost certainly read:
if (!isIE) {
document.getElementById(editor).contentWindow.document = "on";
}
As it stands you're asking non-IE browser to find an element with id null, rather than an element with id 'content'.
However, that won't get you a text caret in your IFrame, even if it does make it editable.
The best I could come up with was:
document.getElementById(editor).contentWindow.document.style.cursor = "text";
Which turns the cursor into a caret on the first line of the iFrame (i.e. at the top), presumably because that's the only editable bit at that point.
You have to set this property when the iframe loads.
var edit = document.getElementById(editor).contentWindow.document;
edit.addEventListener("load", function() {
edit.designMode = "On";
}, false);

Resources