Scroll top after popping up a new window.

This question already has an answer here:

  • Check if element is visible after scrolling 38 answers

  • 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.


    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);
      });
     });
    

    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.

    链接地址: http://www.djcxy.com/p/83340.html

    上一篇: jQuery:在水平滚动上告诉哪个元素在视口中

    下一篇: 弹出一个新窗口后滚动顶部。