I have a WinForms program written on .NET 2 which hosts a webbrowser control and renders asp.net pages from a known server.
I would like to be able to drag, say, a tree node from a treeview in my winforms app into a specific location in the hosted web page and have it trigger a javascript event there.
Currently, I can implement the IDocHostUIHandler interface and getting drag\drop events on the browser control, then call Navigate("javascript:fire_event(...)") on the control to execute a script on the page. However, I want this to work only when I drop data on a specific part of the page.
One solution, I suppose, would be to bite the bullet and write a custom browser plugin in the form of an activex control, embed that in the location I want to drop to and let that implement the needed drag\drop interfaces.
Would that work?
Is there a cleaner approach? Can I take advantage of the fact that the browser control is hosted in my app and provide some further level of interaction?
Take a look at the BrowserPlus project at Yahoo.
It looks like they have built a toolkit so that you don't have to do the gritty work of writing the browser plugin yourself.
If you can find out the on screen position of the part of the page you are interested in, you could compare this with the position of the mouse when you receive the drop event. I'm not sure how practical this is if you can get the info out of the DOM or whatnot.
As an alternative could you implement the mouse events on the bit of the page using javascript?
Related
I have a WebView in UWP which is getting some html content (including javascript).
I need a way to track actions performed on the Webview content, for instance if the user has clicked a button I would like to know.
I know https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.webview.scriptnotify
but for this to work javascript has to call window.external.notify().
But the problem is that I don't own this content and it doesn't make sense to ask the owners to change their handler to publish this window.external.notify().
So, is there any way I can track all the user actions without modifiying the content?
I don't think you can accomplish what you're wanting to do with the UWP web viewer.
One alternative to consider is CefSharp which has a WPF implementation of Chromium.
It gives you a lot of hooks and handlers to intercept requests and do a lot of custom work on JavaScript that you don't control. I used it to build a WPF based help system and it allowed me to intercept links to PDFs and videos so that I could display them in special viewers.
I'm making a winform application containing a WebBrowser control. I'm trying to connect to a Web page that contains ads, but it's affecting the loading speed of the page. The adblock plugin for Chrome blocks ads. So is there any way to add that plugin or any other way to achieve the same result?
The adblock plugin is just some js script with some browsers specific metadata on top. You can check the source code here: https://adblockplus.org/source
You can probably sort something out with this (like run the plugin's code after page load)
I haven't looked into it very much but am struggling to find relevant information on the topic. I basically want to create a browser that applies a filter to a webpage by changing colors in a webpage. My guess is that I will have to change the html once loaded or something, would this work? Do I have other options?
PS. I don't just want to make every color darker, I would more like to invert the colors.
Edit:
If any you were wondering, I am talking about the XAML browser component that can be used in a Windows Phone application.
I think the simplest way to do that is to inject some Javascript into your page once it has loaded.
To do that, you need to set the IsScriptEnabled to true on your WebBrowser control and then subscribe to the Navigated event.
When that event occurs you can inject some JS codeby using the WebBrowser.InvokeScript method.
Here is an example of JS code that darken the page : JavaScript: Invert color on all elements of a page
If you are talking about in a PC internet browser, you can find an add-on to execute Javascript automatically, such as Greasemonkey for Firefox. If you are talking about Windows Phone's Internet Explorer, I don't really know what you could do there, as I don't think they allow add-ons.
I am developing an application where I need to drag and drop a browser in my wp7 screen.So
can any body tel me how can we drag and drop a web browser control in a wp7 screen
Code Examples will do good to me
Thank You
Just declare a web browser control in XAML. Designer drag-drop functionality is not the best approach if you are arranging controls on any container, other then Canvas.
Usage would be like this;
<StackPanel>
<WebBrowser .../>
</StackPanel>
If you are talking about allowing the user to be able to drag the control within the running app then you can't do this with the control directly and still allow touch manipulation of the content. You could do this by putting a transparent control over the top of the WebBrowser and making that draggable and duplicating the movements of this transparent control to update the WebBrowser's position.
Such behaviour in an app would likely be very unusual and I'd recommend testing such interaction with users thoroughly and also exploring other ways of achieving the same result.
The easiest way to handle drag and drop in the Web Browser control is to handle the Navigate event. You can also capture drop operations inside of the the actual HTML document using window.ondrop but if you need to capture full filenames the Navigate event on the control in the .NET host application is your best bet.
For more detail on how this work take a look at this blog post:
https://weblog.west-wind.com/posts/2017/Mar/10/Dragging-and-Dropping-Images-and-Files-into-the-Web-Browser-Control
I am currently playing a little bit around with the development environment. At the moment I am writing a small app, which adresses a Webbrowser-Control.
Therefore I was looking for an opportunity, to show the URL-bar and maybe manipulating the URL via input of the user. Is this anyway possible, or not implemented for the webbrowser control?
Thanks in advance!
The WebBrowser control itself doesn't have a URL bar. It is simply a control that has the ability to display HTML and run Javascript. The easiest way way to simulate one would be to create a textbox. You can then use its Navigate method to load the webpage:
myWebBrowserControl.Navigate(myTextboxUrl.Text);
Alternatively, you can use the WebBrowserTask, but your app loses all control of the user's activities within this task.
I think it'd be easier to just launch the web browser task directly. Customizing the URL bar would probably require rolling your own.
Here's a related question about opening the browser: Open webbrowser with specific url in WP7