I have a simple Xamarin Forms project that has a WebView which is used to load an ASP.NET website on our intranet. Currently there is only a Android implementation in the solution.
The website being loaded includes several CSS and Javascript files. The CSS files are being linked via link rel tags, while the Javascript files are linked using script src tags.
I have put alert statements in a script on the page itself, as well as in the linked Javascript file. Using a browser on my computer, both alert statements show up, however in the WebView, only the alert for the page shows up.
I've also tried using the WebView.eval method to call a Javascript method in the linked file as well as one defined on the page itself. Calling the method defined on the page worked, but the one in the linked Javascript file didn't.
All that has lead me to the conclusion that for some reason the WebView isn't loading the Javascript files indicated by the script src tags.
From research I have done, there is mention of having to include the Javascript file itself in the Android and iOS projects, but those seemed to be for situations where the WebView source was being set to a constructed website, not pointing to an existing web site.
Here are samples of how the files are linked:
<link rel="stylesheet" href="/App_Themes/wms.min.css" />
<script src="/Scripts/wms.js"></script>
I have tried using absolute paths, which didn't work either:
<script src="http://path.to.site/Scripts/wms.js"></script>
What am I doing wrong? How do I get the the linked javascript files to load and be usable?
Edit: Update, apparently the file was being linked and loaded correctly, it was just being cached by the webview and or the android device or emulator.
Because of that, when I made changes to the javascript file, and tried to use / view those changes via the webview, it wasn't being reflected, since a new copy of the javascript file wasn't pulled from the website.
However, when I gave a new name to the javascript file and linked to that, the webview get the new file, and all my changes were there and it behaved as expected.
So, I will be using the clear cache method outlined here to clear my change when the app starts: http://www.tipsabc.com/2015/xamarin-froms-how-to-clear-webview-cached-files/
That way, every time it starts it will force the webview to get a fresh copy of all the files.
Related
On a customers site certain pages (two that I know of) trigger the download of a TeamViewer exe file that is on the server instead of showing the linked aspx page.
This was brought to our attention today and I'm not sure when it started.
I've gone over the routing and generic page handler in our system and I don't find anything out of the ordinary.
Is there any known reason this could happen that relates to server configuration or similar?
I've tried it in multiple different browsers and the download is triggered in each of them (Chrome, Chromium and Opera).
The file in question is not linked in the pages. The contents of the pages are being fetched from a database using the same system as the non-problematic pages.
I found the issue.
Turns out someone added a redirect to this exe file in web.config which matched "tv" (for TeamViewer) in the url, and matched for example "tjanster-programutveckling" which was one of the problem pages.
I guess whoever added that redirect expected it to only apply to the whole url, not just a partial match.
I've commented out this redirect and now the pages load properly.
I am working on scrapping of website. so i make one desktop application for that.
I check website using inspect element then i can see whole data of website but when i try to check website data using page source(ctrl+U) then there is nothing.
means i can't find any website data in page source but can see in firebug(inspect element).
because of this when i am trying to get data using c# coding then i am getting only page source data which doesn't contains any website data only contains schema(structure) and js links.
see below image of firebug.
And this is page source image.
You met the js-powered site. The content is dynamicly loaded thru js, thus it's not visible in page-source. Turn to the scrape libraries that support js code evaluation. See here an example.
I have an html file (which consists of both text and images) in my Documents library (it need not exactly be over there, what I mean to emphasize is - it's not in the internet and not included within the app package since it's dynamic content and created after the app has been deployed).
I want to display the contents of this page within a WebView. How would I go about doing that ?
You can (and should) copy your HTML Files to the LocalState Directory of your App which sits here: C:\Users\YourUSerName\AppData\Local\Packages\YourApp\LocalState.
You then can Access this with: ms-appdata:///local/
Very Basic example:
string url = "ms-appdata:///local/myWebpage.html";
webView.Navigate(new Uri(url));
You can find a lot of Information and samples in this sample download: https://code.msdn.microsoft.com/windowsapps/XAML-WebView-control-sample-58ad63f7
I have a Web Browser Control in windows application. I want to save page at specific folder with CSS files and JS files. I have used webBrowser1.ShowSaveAsDialog() method but by this user can save page at any location instead of my application folder.
So, how can I save pages with folder structure to my location without showing pop up menu?
Good question!! all the browsers do it, iMacros ($495-$990) does it
Selenium, phantomjs, slimer, watir, etc CAN'T do it,
the closest i have seen to that sort of functionality is...
http://www.codeproject.com/Articles/2847/Automated-IE-SaveAs-MHTML
which uses c++ to hack the save as dialog.
You'd think that SaveAs webpage complete would be just another
method on the browser control. But it doesn't seem so. I want
this functionality as well -- sorry this question remains unanswered.
I have a winforms app that I would like to add some new features to.
Ideally I would have a new form that would have an embedded browser control. I want the pages in the browser to be 'served' from the app itself ( as opposed to a remote sever ).
The pages will be dynamically created dependent on data from within the App.
Also, how do I cater for references to assets like CSS, Javascript and Image files. Ideally these would need to be handled by the application as well.
How do I do this?
I use this technique in my application. I host a WebBrowser, and I populated it as follows:
public void DisplayHtml(HtmlGenerator gen)
{
webBrowser.DocumentText = gen.GenerateHtmlString());
}
Using this method, I don't have to actually generate a file on my file system with the HTML content.
Use the WebBrowser control.
You can set the DocumentText property to the HTML you want to display. (thanks #Anton Semenov).
Alternatively, you can feed it local file URLs from files that your application creates.
In my test management tool (this one, if I'm allowed to add a link), I have written my own "mini ASP" by having HTML pages with C# code inside and then processing them dynamically by converting the page into C#, compiling the code and then execute it.
Pay attention that this might populate the application domain since you cannot unload the dynamically loaded script code.
An excerpt from such a HTML file looks like:
<div id="title">
<img src="../_Shared/images/32x32/component_blue_view.png" />
<h1>Test case "[$=tc.Title$]" - Details</h1>
</div>
Here, the [$= and $] are the equivalents of <%= and %>.
In another project I did something similar with the Microsoft VBScript interpreter; instead of compiling the code to C#, I compile it as a VBScript and let it execute then by the VBScript engine of the Microsoft Scripting host.
To handle resources like images and CSS, you can simply ship your own, integrated web server. I successfully did this with several projects by including this CodePlex project.