Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. iframe question(control the scroll bar)

iframe question(control the scroll bar)

Scheduled Pinned Locked Moved Web Development
helpjavascripthtmlcomsysadmin
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Wang1983
    wrote on last edited by
    #1

    I have a iframe in my page a.html, the iframe points to page b.html, every time when the page loaded completely, the iframe display the top of page b.html My request is to scroll down the iframe so to display the bottom of b.html when page loaded I can invoke below javascript when body.onload event occur: windows.my_frame.scrollTop = 800; it works with b.html which is on the same server with a.html but if the src of the iframe points to the page out of the server(http://www.google.com), the script invoke run time error which means I have no right to set the scrollTop property I can not find and solution or even any explanation on the internet, so came here. Thanks for the help!!!

    J G 2 Replies Last reply
    0
    • R Robert Wang1983

      I have a iframe in my page a.html, the iframe points to page b.html, every time when the page loaded completely, the iframe display the top of page b.html My request is to scroll down the iframe so to display the bottom of b.html when page loaded I can invoke below javascript when body.onload event occur: windows.my_frame.scrollTop = 800; it works with b.html which is on the same server with a.html but if the src of the iframe points to the page out of the server(http://www.google.com), the script invoke run time error which means I have no right to set the scrollTop property I can not find and solution or even any explanation on the internet, so came here. Thanks for the help!!!

      J Offline
      J Offline
      Jaffer Mumtaz
      wrote on last edited by
      #2

      Please explain where have you placed your script and from where do you call it. Just try to alert something in the script to check if its even called or not.

      R 1 Reply Last reply
      0
      • J Jaffer Mumtaz

        Please explain where have you placed your script and from where do you call it. Just try to alert something in the script to check if its even called or not.

        R Offline
        R Offline
        Robert Wang1983
        wrote on last edited by
        #3

        Hi, below is the script function scrollFrame(x, y) { if (window.myFrame&&window.myFrame.scrollBy) { alert("bbb"); var ifr = window.myFrame; ifr.oldPageYOffset = ifr.pageYOffset; ifr.scrollBy(x, y); } } function test() { alert("aaa"); scrollFrame(50, 50); } I call it in the body.onclick() the alert did popup, so means the the function is called but runtime error told me I can not access the property of oldPageYOffset neighter the function scrollBy(x,y) if the frame points url off site

        1 Reply Last reply
        0
        • R Robert Wang1983

          I have a iframe in my page a.html, the iframe points to page b.html, every time when the page loaded completely, the iframe display the top of page b.html My request is to scroll down the iframe so to display the bottom of b.html when page loaded I can invoke below javascript when body.onload event occur: windows.my_frame.scrollTop = 800; it works with b.html which is on the same server with a.html but if the src of the iframe points to the page out of the server(http://www.google.com), the script invoke run time error which means I have no right to set the scrollTop property I can not find and solution or even any explanation on the internet, so came here. Thanks for the help!!!

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          You can not do anything at all to a page that is loaded from a different domain. It's a security restriction in the browser.

          Despite everything, the person most likely to be fooling you next is yourself.

          R 1 Reply Last reply
          0
          • G Guffa

            You can not do anything at all to a page that is loaded from a different domain. It's a security restriction in the browser.

            Despite everything, the person most likely to be fooling you next is yourself.

            R Offline
            R Offline
            Robert Wang1983
            wrote on last edited by
            #5

            Yeah, I got the information. But any idea in other ways about how to realize this requirement

            G 1 Reply Last reply
            0
            • R Robert Wang1983

              Yeah, I got the information. But any idea in other ways about how to realize this requirement

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              If you want to change the scroll position of the page in the iframe, that code would have to be in that page, not in the page containing the iframe.

              Despite everything, the person most likely to be fooling you next is yourself.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups