473,396 Members | 2,003 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,396 software developers and data experts.

click makes page scroll far right

Is it possible to have a javascript function which can scroll a page
to the far right when a link is clicked? Any code examples available?

TIA,
Anna
Jul 23 '05 #1
7 3822
anna wrote:
Is it possible to have a javascript function which can scroll a page
to the far right when a link is clicked? Any code examples available?

TIA,
Anna


Hi Anna,

I'd look at this approach:

function doit(direction) {
if (direction=='r')
window.scroll(700,1) //modify 1st number to change x position
if (direction=='l')
window.scroll(0,1) //modify 1st number to change x position
}

<table border="1" cellspacing="1" width="1400">
<tr>
<td width="222">
<input type="button" value="Right" onclick="doit('r')">
</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
</tr>
<tr>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">&nbsp;</td>
<td width="222">
<input type="button" value="Left" onclick="doit('l')">
</td>
</tr>
</table>

Jul 23 '05 #2
anna wrote:
Is it possible to have a javascript function which can scroll a page
to the far right when a link is clicked? Any code examples available?

TIA,
Anna


Code example here:

http://www.w3schools.com/js/tryit.as...js_scrollright

Jul 23 '05 #3
I tried the examples and it works fine with input type=button but
doesn't work with type=image.

Any way to make it work? Using the image look less clunky.

<input type="button" value=">>" onClick="alignRight();"> //this works

<input type="image" src="/icons/redarrow.gif" onClick="alignRight();">
//rather have this work
Jul 23 '05 #4
What I ended up doing and it works for browsers NN4, NN7, and IE6.

<a href="javascript:window.scrollTo(1000,0)"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>
Jul 23 '05 #5
SOLUTION:
What I ended up doing and it works for browsers NN4, NN7, and IE6.

<a href="javascript:window.scrollTo(1000,0)"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>
Jul 23 '05 #6
FOLLOWUP
if (navigator.appName.indexOf("Netscape") != -1 &&
parseFloat(navigator.appVersion) < 5 ) {
if (document.width > window.innerWidth) {
document.write('<a
href="javascript:window.scrollTo(1000,window.pageY Offset)"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
}
} else {
if (document.body.scrollWidth > document.body.clientWidth) {
document.write('<a
href="javascript:window.scrollTo(1000,document.bod y.scrollTop)"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
}
}
Jul 23 '05 #7
anna wrote:
FOLLOWUP
Do you really know what a followup is and what medium you are using?

<http://www.faqs.org/faqs/usenet/posting-rules/part1/>
if (navigator.appName.indexOf("Netscape") != -1 &&
parseFloat(navigator.appVersion) < 5 ) {
Nonsense. <http://pointedears.de.vu/scripts/test/whatami>

Better:

if (typeof document.width != "undefined"
&& typeof document.innerWidth != "undefined")
{
if (document.width > window.innerWidth) {
document.write('<a
href="javascript:window.scrollTo(1000,window.pageY Offset)"><img ^^^^^^^^^^^^
Nonsense. <http://jibbering.com/faq/#FAQ4_24>

Better:

if (document.width > window.innerWidth) {
document.write(
'<a
+ ' href="javascript:void(window.scrollTo(1000,window. pageYOffset))"'
+ ' onclick="window.scrollTo(1000, window.pageYOffset); return false"'
+ '><img ...');
src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
This will not work as supposed if you provide only one link with two images.
}
} else {
if (document.body.scrollWidth > document.body.clientWidth) {
Again you did not test for those host objects and their properties before
accessing them. See above.
document.write('<a
href="javascript:window.scrollTo(1000,document.bod y.scrollTop)"><img
See above.
src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
See above.
}
}

PointedEars
Jul 23 '05 #8

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

Similar topics

8
by: George Hester | last post by:
In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to...
5
by: MacKenzieMouse | last post by:
Is there an easy way to have the page scroll to the next button? When I populate a drop down list box, I have to use the arrow key or the mouse to scroll down. I would like for the page to be...
4
by: Lenny Shprekher | last post by:
I am using regular server site ASP.NET button to execute function. Works fine, issue is that when I call page-refresh on IE after click I done it is calling same event again. Could anybody suggest...
1
by: xx75vulcan | last post by:
Can someone look at this page I've been handed. It's got a javascript menu on it. To have the menu retain it's place on the page, it's encoded in a <span Style=:"position:relative;"> tag. ...
2
by: knkk | last post by:
I have an iframe in a page (with a name to the iframe), and in that iframe I have several anchors <a name="something"> There are links in the iframe that look like <a href="#something"> ...
2
by: siddu | last post by:
Hi, My page Items are moving when I minimize my webpage. I am having header,footer and sidebar. when ever I minimize my page and if I scroll right then the sidebar also coming front and the...
2
by: Msleh08 | last post by:
Hello. The code below shows a basic html text file with a highlighted bar that scrolls over each <tr> using your up/down arrow. If you notice, when you scroll using your up/down arrow the page jerks....
15
Claus Mygind
by: Claus Mygind | last post by:
I have a <div> tag in my app that I minimize on the screen thereby only showing the top line of the content in that division. The user activates the content (maximizes the content) with the...
4
by: cvermar | last post by:
Hi, I'm new here. I'm teaching my self to write a web site to help my sister's new business. It's in a three column format. I put an small iframe on the main page's right column to show her...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.