Javascript Popup Scrolling

Of course, there is an easy way to do this. I need to load a page in a java script popup. But the content that I need to show in the window is the way down the page. Is there any way to go to this part of the page? (So, go to the vertical scroll coordinate?) (Also, I cannot edit the page displayed. Only a link to it)

Any help is much appreciated!

+4
source share
3 answers

Assuming you cannot link to the bindings, but the page you load in the popup is in the same domain that you can use something like this:

  • load popup
  • set onload event for popup after loading it
  • the popup page will scroll down after it loads.

You can customize this, for example. you can provide an additional parameter openInPopUp () with the exact position for scrolling.

Here is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <script language="javascript" type="text/javascript"> function openInPopUp(link) { // (1) load the popup newwindow = window.open(link.href, 'name', 'height=300,width=200,resizable=1,scrollbars=1'); // (2) set the onload event newwindow.onload = function() { scrollDown(); }; return false; } function scrollDown(){ // (3) scroll down newwindow.scrollTo(0, 200); } </script> <title></title> </head> <body> <p> <a href="popup.html" onclick="return openInPopUp(this)">open link to popup and scroll down</a> <br/><br/> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum<br/> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum<br/> </p> </body> </html> 

If you want to download content from a different domain than the calling page, this will not work, but will result in a permission error.

Details for the scrollTo function

0
source

The easiest way is to associate the element with the page by adding its id after the hash in the URL. those. when you open a popup

 window.open('pagename.html#element-to-show','mywindow','width=400,height=200') 

where "element-to-show" is the identifier of the element that is on the page.

+3
source

Use HTML bindings and load page.html#myanchor into the popup (instead of page.html ).

http://www.w3.org/TR/html4/struct/links.html

+1
source

All Articles