0

First question but I really am in a jam.

I have a webpage render which is working perfectly. However, I need to be able to control the initial display position (almost like a href #anchors in HTML) but without any access to the site content.

From as far as i can see i have no access to the scrollBars other than the bool to enable / disable..

Is there anything i can do to even force a scroll down of 20% for example, and then I can create a form to adjust later on.

Any assistance would be HUGELY appreciated although from what I have researched it seems unlikely.

I have the regular windows WebBrowser Render

private System.Windows.Forms.WebBrowser m_webBrowser;

Thanks !

--This is for c# standalone application.. Not WebBased.

Pogrindis
  • 7,755
  • 5
  • 31
  • 44

2 Answers2

1

Have you tried using jquery?

I personally use the animate method from jquery to scroll to certain elemnts in my webpage.

Example:

 $('html, body').animate({scrollTop: $('#the-element-you-want-to-scroll-to).offset().top}, 1000);

PS: For the last parameter you can control the time it will use to scroll to destination, that offering you a nice effect.(in milliseconds)

Freeman
  • 5,691
  • 3
  • 29
  • 41
  • I would be able to do it no problem if i had access to the Site page, however its from a 3rd party site, so the c# application will need to render the WebPage and "automatically" scroll down to a certain position.. This is a c# only related.. Sadly i cant bring the beloved jquery into it! :( – Pogrindis Sep 19 '12 at 16:55
  • you can try and render the page as usual, but this time with javascript/jquery inserted somewhere(on a event would be nice), altough i used this in MVC not webforms. – Freeman Sep 19 '12 at 16:57
  • Sorry i should have explained that better .. This is for c# standalone application.. Not WebBased. – Pogrindis Sep 19 '12 at 16:59
  • sorry then, thought its a webpage rendering in a browser. – Freeman Sep 19 '12 at 17:03
  • interestingly this came in handy! Marked it as the better answer! – Pogrindis Jun 29 '13 at 04:01
0

I managed to resolve it using a strange method..

I basically injected some javascript into the rendered HTML manually.. Then the rest was easy.

i used something like this :

            string updatedSource = WebBrowser.DocumentText.Replace("Google", "Foogle");
            string extraSource =
            "<html><body>Script goes here <br/>" +
            "<div><p>BLA BLA BLA</p></div></body></html>";


            WebBrowser.DocumentText = extraSource + updatedSource;

            WebBrowser.Update(); 

Maybe it will help someone.

Pogrindis
  • 7,755
  • 5
  • 31
  • 44