ScrollTo() SetTimeout() Postioning Popup??

Discussion in 'JavaScript' started by brianj, Apr 26, 2009.

  1. #1
    Hi everyone..

    i know Popups are a bad thing, but for my personal desktop i'm trying to create a popup that scrolls a page (news site etc.) down to a fixed position:

    //simple popup that works
    <a href="javascript:void(0);" 
    onClick="window.open('http://site.com/news', 
    'popup', 'location=no, menubar=no, scrollbars=0, 
    status=no, resizable=no, width=400, height=300');
    ">Open Popup</a>
    Code (markup):
    //???
    window.scrollTo(350, 0);
    window.setTimeout ( ??? )
    
    Code (markup):
    Does anyone know how to apply the SetTimeout() to make the scroll actually work?

    Thanks for help!
     
    brianj, Apr 26, 2009 IP
  2. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    any chance at all?
     
    brianj, Apr 26, 2009 IP
  3. JavaScriptBank.com

    JavaScriptBank.com Peon

    Messages:
    141
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you must place you code into a function, then use setTimeout method to execute

    setTimeout Method

    hope this is useful
     
    JavaScriptBank.com, Apr 27, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    something like this will work:
    
    <a href="javascript:openWindow();" >Open Popup</a>
    <script type="text/javascript">
    var myPopup;
    function openWindow() {
    myPopup = window.open("mynews.html", 'popup', 'location=no, menubar=no, scrollbars=yes, status=no, resizable=no, width=400, height=300')
    setTimeout("myPopup.scrollTo(0, 350);", 2000);
    }
    </script>
    
    Code (markup):
    But... Most (if not all) browsers will only allow javascript to scroll the contents of a popup IF the page that is loaded is from the same host as the page that has created the popup.
    I'm not sure if there is a way around this, maybe loading a local file that has a frame containing the intented target, and then scrolling it from there... But it may not even allow that.
     
    camjohnson95, Apr 29, 2009 IP
  5. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #5
    set id="anchor" and the source as mynews.html#anchor, may work w/o anything too fancy.
     
    dimitar christoff, May 1, 2009 IP