as the title say, I would like to disable client from dragging or sliding out an element into a c# winforms webview to the desktop.
This will avoid the client from making an icon on desktop to the current page link.
Is it possible to disable this?
Insert a piece of JS code into the page:
document.ondragstart = function () { return false; };
Related
I am creating a webview2 wpf application, everything works well till now, but when I tried to load HTML file which is having youtube link, It's worked well along with autoplay .
But when I change the HTML file to some another site , the audio of youtube video still playing in background and webview2 load the new content.
I want something to disable the cache to be stored will runtime instead of clearing the cache.
If someone is having any idea related to above issue please help
This is the common issue faced by the webview2 when external site media player is played.
To overcome this issue you have to create a new instance of webview2 before you load second content to webView, this will create new Webview Page but still the UI will not stop the audio, so use Webview.dispose() as well.
WebView.Dispose()
Note : this will give you issue related to Null object reference for the 1st time .
So you have the check the the object before doing dispose.
Code should be like this :
MainPage :
WebViewPage webpage;
private void updateNewContent ()
{
...
WebView2 webView2 = Mywebvew2; // MYwebview2 is UI object from webviewPage,
//you have to pass this object from webview Page
if (webView2 != null)
{
webView2.Dispose();
}
webpage = null;
webpage = new WebViewPage();
GridPrincipal.Children.Add(webpage);
...
}
I have a Blazor Server web app; .NET 5.
I am running into frustrations related to navigating between pages in my web app:
When I use NavigationManager.NavigateTo(uri, true), I am unable to open links using my scroll click (which would open the link in a new browser tab if I were to use href="uri" instead). It opens a new tab, but loads the same page I was already on.
When I use href="uri" instead, the scroll-click works. However, it introduces a new problem: with a 'normal' left-click, the new page loads but retains the scroll position of the previous page in a mobile browser (I have tested with mobile Safari, as well as the mobile emulator in Chrome).
I need to be able to scroll-click into a new tab, as well as have a new page load without retaining the previous page's scroll position. Any tips?
Assuming that you are using the onclick event:
The onclick event does not listen for the scroll wheel click. To fix this just use the onmousedown event instead:
<button class="btn btn-dark" #onmousedown="OnClick">Test</button>
#code {
private void OnClick()
{
NavigationManager.NavigateTo("/counter", true);
}
}
I am using Webview to displays an html page that contains 2 inputs of type text and a submit button.I want the app user to be able to fill these fields on the app before launching the webview.Therefore taking the user directly to the result of the search.
Apparently the webview.Document is no longer available.
Any suggestion ?
Once the HTML is loaded into WebView, you can call a method called InvokeScriptAsync through which you can invoke some kind of Javascript.
await myWebView.InvokeScriptAsync("eval", new string[] { "var elem = document.forms[0].submit();"});
This way you can fill the input field, click a button or whatever you need.
I am developing a browser app for Windows Phone 8. I want to detect the scroll position, so that I can show the address bar only when user is at top of the page. I also want to restore the current scroll position after a page refresh.
I cannot inject javascript into the page because obviously the content is from all over the web.
So far I am able to determine if user is scrolling up or down based on this idea.
If I can inject javascript, I probably could use InvokeScript and detect if page scroll is at the very top
window.onscroll = function(ev)
{
var B= document.body; //IE 'quirks'
var D= document.documentElement; //IE with doctype
D= (D.clientHeight)? D: B;
if (D.scrollTop == 0)
{
alert("top");
}
};
DEMO
So I wonder if anyone has any suggestion to achieve this. Thanks.
EDIT
Is it possible to use IFRAME and place my javascript there while the external websites are loaded inside the IFRAME?
I have an HTML page with this script:
<Script>
function Run()
{
alert("The Content Here");
return true;
}
</script>
<button onclick="Run();">I Want It Now</button>
Lets say that I opened this page with firefox or Chrome. And lets say that I clicked on the button "I Want It Now" and the page shows me the alert:
The Content Here
How can I insert the alert content into a string in my VB.NET project? I know that I can use the alert window handle to get the label handle and then extract (grab) the text of the alert, but I don't think that this is the best way to do it. Is there another way to pass (or get) information from the page (not from webbrowser control or by using webClient.DownloadString) into my VB.NET (or C#) project?
i don't this it will easy to use js without the webbrowser control by the way if you changed your mind and want to use a web browser control , you can do it like this :)
WebBrowser1.Document.GetElementById("NAME").InvokeMember("click");