devdoe
devdoe

Reputation: 4325

Scrolling window on load

I submit some values from a form to another page... that page returns with a url like: localhost:8084/abc.jsp?ok=true

I applied a function on 'onLoad' of my page body named checkscroll()... and this function in javascript should scrolls my window..

CODE: for javascript

function checkscroll()
                  {

                     var rr = new String();
                        rr = request.getParametr("ok");
                     if(rr=="true")
                         window.scrollBy(0, 60);

                  }

what is wrong in this code ?

Upvotes: 0

Views: 151

Answers (2)

Sarfraz
Sarfraz

Reputation: 382646

Use the location.search:

var qs = location.search;
if (qs.indexOf('ok') >=0 && qs.indexOf('true') >=0) {
  window.scrollBy(0, 60);
}

Or

var qs = location.search,
         param = qs.split('=')[0].split('?').join(''),
         val = qs.split('=')[1];


if (param === 'ok' && val === 'true') {
  window.scrollBy(0, 60);
}

Upvotes: 1

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167162

You have used request.getParametr, which is a JSP / Java function, not in JavaScript. You need to use location.search for getting the parameter.

The code window.scrollBy(x,y) works only in Firefox. What browser are you using? For a better compatibility, use jQuery's animate() function. To use that, you can try this script.

function checkscroll()
{
    var rr = location.search;
    rr = rr.indexOf('ok');
    if(rr=="true")
        $("html, body").animate({scrollTop: 60}, 'slow');
}

Let us know, if this solves.

Upvotes: 1

Related Questions