1

So currently on button click I'm popping up a new window that goes to some website. But not only do I need to pop open to this new site but I also need to scroll down a little on the popped up screen. Here is what I'm currently doing:

$(document).ready(function () {
  $('.popup').click(function(event) {
    event.preventDefault();
    window.open("https://www.spmet.aspx", "popupWindow", "width=1400,height=600,scrollbars=yes");
    setTimeout(function() { scrollTo(0,150) }, 1000);
  });
});

This currently opens the window successfully but how do I amend a change that will scroll to a particular spot in the site.

Bitwise
  • 6,603
  • 16
  • 49
  • 122

3 Answers3

0

Because You open a new window, js is loaded second time and click event wasn't executed. You can use something like:

$(document).ready(function () {
    if (window.location.href.indexOf("my_url") > -1) {
       $('html,body').animate({ scrollTop: "0px" }); // or 150px
    }
});

or use some global variable for setTimeout and break it after execution.

Wordica
  • 1,996
  • 2
  • 26
  • 45
0

your code is runnning in the parent window, not in the pop up one. If you canĀ“t put int in the pop up target, try scrolling by reference adding "#btnLogin_div" top the url like this:

$(document).ready(function () {
 $('.popup').click(function(event) {
   event.preventDefault();
window.open
("https://www.spmet.aspx", 
 "popupWindow", "width=1400,height=600,scrollbars=yes");
    setTimeout(function() { scrollTo(0,150) }, 1000);
  });
 });
0

Since you are opening a new window; the js on your old page is not used; you have to add the scroll js on the new page you are loading. This is good cause otherwise I could have you go to a page and phantom click on stuff, which would not be good.

You can get around it by opening the page in an iframe; where you can scroll your iframe window.

Gerrit B
  • 184
  • 1
  • 9