473,383 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Prevent scrolling

I'm working on a code generator for documentation of VBA projects. It outputs HTML docs, including simple JS. I don't have much experience with JS however, so I need some help with this sample output:

http://www.algonet.se/~gustafl/test/frmCalcMany.html

Whenever I click 'Show source' after scrolling down a bit, the page instantly jumps to the top of the page, which may hide the source. I understand this is because of href="#", but I don't know what I could do instead. The behavior I want is of course to show/hide the source, but without scrolling.

Gustaf
Sep 25 '08 #1
6 4131
Gustaf schreef:
I'm working on a code generator for documentation of VBA projects. It
outputs HTML docs, including simple JS. I don't have much experience
with JS however, so I need some help with this sample output:

http://www.algonet.se/~gustafl/test/frmCalcMany.html

Whenever I click 'Show source' after scrolling down a bit, the page
instantly jumps to the top of the page, which may hide the source. I
understand this is because of href="#", but I don't know what I could do
instead. The behavior I want is of course to show/hide the source, but
without scrolling.
Change:

onclick="ToggleShowSource

Into:

onclick="return ToggleShowSource
When this doesn't work, have ToggleShowSource() return false as its last
statement.
JW
Sep 25 '08 #2
Janwillem Borleffs wrote:
Change:

onclick="ToggleShowSource

Into:

onclick="return ToggleShowSource
When this doesn't work, have ToggleShowSource() return false as its last
statement.
I'm not sure I understand exactly. The result from adding 'return' to each call is that the link disappears completely when clicked, and no source is shown.

Gustaf
Sep 25 '08 #3
SAM
Le 9/25/08 12:27 PM, Gustaf a écrit :
>
I'm not sure I understand exactly. The result from adding 'return' to
each call is that the link disappears completely when clicked, and no
source is shown.

Gustaf

example :

<a href="apage.htm" onclick="alert('with JS no link'); return false;">
test 1
</a>

<script type="text/javascript">
function test() {
alert('with JS enabled : no link');
return false;
}
</script>

<a href="apage.htm" onclick="return test();">
test 2
</a>

--
sm
Sep 25 '08 #4
Gustaf schreef:
I'm not sure I understand exactly. The result from adding 'return' to
each call is that the link disappears completely when clicked, and no
source is shown.
End each onclick with a "; return false". Example:

onclick="ToggleShowSource('show4');ToggleShowSourc e('hide4');ToggleShowSource('source4');
return false"

HTH;
JW
Sep 25 '08 #5
On Sep 25, 11:27 am, Gustaf wrote:
Janwillem Borleffs wrote:
>Change:
>onclick="ToggleShowSource
>Into:
>onclick="return ToggleShowSource
>When this doesn't work, have ToggleShowSource() return false as its last
statement.

I'm not sure I understand exactly. The result from adding 'return' to each call is that the link disappears completely when clicked, and no source is shown.
The point of adding the - return - is to have the function that is
called in response to click events return a boolean false value and so
cancel the navigation that is the default action taken when you click
on a link ('#' being, effectively, the URL of the top of the current
page, so you navigate to the top of the page).

The change (or rather, that specific change) doesn't work for you
because your onclick attribute code is:-

onclick="ToggleShowSource('show2');ToggleShowSourc e('hide2');ToggleShowSource('source2');"

- and that translates into a function with the form:-

link.onclick = function(event){
ToggleShowSource('show2');
ToggleShowSource('hide2');
ToggleShowSource('source2');
}

- and just sticking - return - at the beginning turns it into:-

link.onclick = function(event){
return ToggleShowSource('show2');
ToggleShowSource('hide2');
ToggleShowSource('source2');
}

- which is going to cancel the naviation (if ToggleShowSource returns
false) but the return happens before the second and third calls to
ToggleShowSource and so some of the hiding/showing that is wanted will
not happen.

There are several ways around that; putting - return false; - at the
end of the onclick attribute code would work (even if it is a bit
clunky, style-wise).

An alternative would be to stop using links for the triggers and
instead use <input type="button"elements (styled to resemble links
if necessary) as they don't navigate when you click on them so there
is no default to be cancelled.
Sep 25 '08 #6
Many thanks everyone, and good explanation!

Gustaf
Sep 25 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: JimO | last post by:
I teach HS computers and one of my kids has a web site with a textbox of info that the user can scroll down and read. The problem is that users can also enter text into it. Is there a way, or a...
1
by: Aravind | last post by:
Hi folks. I have a form that has a form header and form footer, which has a few command buttons. When I open the form, I have to scroll the form from left to right to view my data. The thing is,...
0
by: Steve | last post by:
The treeview has this habit of scrolling when you change the tree's selection so that the selected item is visible. 9 times out of 10 this is the behavior that you'd want, but what do I do to...
0
by: nicholas | last post by:
Is there a way to prevent that when scrolling the mouse wheel the values in a selected dropdownlist change? THX
1
by: Solx37 | last post by:
I am trying to figure out how to prevent scrolling when I append text. It scrolls to the bottom whenever I use AppendText. It jumps to the top whenever I += text to the Text property.
5
by: Kent Briggs | last post by:
VB 2005 Express. I have a readonly multiline textbox with a vertical scrollbar. I'm programatically adding text to it with textbox1.appendtext(mytext) and it scrolls automatically. However, I only...
4
by: Viken Karaguesian | last post by:
Hello all, Can I prevent something, say a <div>, from scrolling when the page is scrolled? I know that with CSS, "background-attach: fixed" will anchor the background element and prevent it from...
1
by: Eric Wong | last post by:
Using Tkinter, I have a Canvas with vertical Scrollbar attached. At runtime, I dynamically create Checkboxes on the Canvas, each one on a different row. When I add a lot of Checkboxes, instead of...
0
by: deko | last post by:
I'm using VS05/.NET 2.0 with a TrackBar control in a Windows Forms application. I need to be able to manually scroll the trackbar (hold down left mouse button and drag), but I need to prevent...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.