click makes page scroll far right

A

anna

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
 
A

anna

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
 
A

anna

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>
 
A

anna

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>
 
A

anna

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.pageYOffset)"><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.body.scrollTop)"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
}
}
 
T

Thomas 'PointedEars' Lahn

anna said:

Do you really know what a followup is and what medium you are using?

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.pageYOffset)"><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.body.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top