0

I am trying to figure out how I can get all my links to scroll to the top of the page as well as open up the desired page in my iframe. Is this possible? I need the link to perform two different functions.

Alarm Standard

                <script>
                    function myFunction() {
                    // Scroll to top
                                document.body.scrollTop = document.documentElement.scrollTop = 0;

                    // Open up a link in my iframe
                            <A HREF="DocDisplayCategory.cfm?CategoryID=47" TARGET="MainWindow">
                            </A>
                                  } 
                </li>
                </script>

2 Answers2

0

You can just use an event handler.

<a href="#" onClick="myFunction();" >Click Me</a>

<script>
    function myFunction() {
        // Scroll to top
        document.body.scrollTop = document.documentElement.scrollTop = 0;

        // Open up a link in my iframe

        document.getElementById('frame1').src="http://www.foo.com/" 
    }
</script>
ATOzTOA
  • 34,814
  • 22
  • 96
  • 117
0

For the scrolling have a look at this here; Scroll to the top of the page using JavaScript/jQuery?
To open a link in an iframe just specify the target

You could event automate the target creation using jquery too.

Community
  • 1
  • 1
Stefan
  • 2,164
  • 1
  • 23
  • 40