Is it possible to embed only a specific portion inside of a page(i.e. div) on the WebView control in UWP?
The webview doesn't include an address bar and so will only show pages that you load or can be navigated to from those pages. If you can control what is loaded you can show only the pages you wish.
If you don't have control over the HTML of the site, you could prevent access to pages you don't want by handling the NavigationStarting event and canceling the navigation if it's to a page you don't want displaying.
No, assuming by a "portion" of a website you mean a portion within a page. However as Matt said, if you only want to show a certain page, you can of course navigate to the relevant web page and then control what navigation links you allow through his method.
If you did indeed mean only a portion within a page, the options aren't attractive. Theoretically you could pull down the html of a site with an Http request and then parse it to filter out what you didn't want, store it locally, and then load that local page in the webview. However I think it would add significant overhead, could create conflicts with javascript or whatever else the site might be using, among other things. But hey maybe if it's a very targeted use-case you might be able to play with it.
If in your scenario though you also control said website the app is accessing, then I'd just enable specific URLs to offer up the desired versions of your site when the app requests 'em.
Note 100% sure, but i can give a hit to embed external part of a any html content to a website opened in webview control.
var result = await this.webView.InvokeScriptAsync("eval", new[] { "document.documentElement.outerHTML;" });
string result = await this.webView.InvokeScriptAsync("eval", new [] {"document.getElementById('tablePrint').innerHTML = myTable;" });
Add HTML content through java script.
Hope that will help
Related
Hello guys I have an issue bugging me for the past few weeks.
What I'm trying to accomplish: I need a webbrowser control with the ability to change user agent (once at start) and referrer. But most important The ability to see the urls responses. What I mean by that for example if you navigate to a website you get back Images/Javascripts files/Dyanmic URLS in response I need access to those urls which some of them have dynamic variables (Regular Webbrowser Control will not show you those & you can't access it in any way beside using fiddler core).
I was able to do that with webbrowser + fiddlercore I can see and do what ever with those urls addresses. The problem was if you run few instances of this program (or sometimes once if the program has some automation to work with the url responses) It gets stuck or doesn't work. I tried fixing it and making it work but it's kind of a hacky solution that doesn't work right. I need a simple way to access those urls just as if you used httpwebrequest but as a webbrowser. Why I need it as a webbrowser? The way I work I need the execution of all the tracking pixels and scripts and images etc.. a normal webbrowser behaivor in httpwebrequest you can't just navigate and all the scripts will be execute as webbrowser, or can you?
Using the System.Windows.Forms.WebBrowser control in a WinForms app, set the webBrowser.URL property to the URL of the page you're interested in.
The webbrowser's DocumentCompleted event fires after the page has loaded. Any dynamically loaded JavaScript should be done by then. Hook the DocumentCompleted event and use the webbrowser.Document.Images to get a list of all image elements on the page. From those images you can get their SRC attributes which contains their URLs including any query parameters hanging off the end. You can use webbrowser.Document.Links to get a list of all hyperlinks on the page. For other HTML elements of interest, you can use GetElementsByTagName("foo") to fetch all elements with that tag name from the page, then dig into their attributes to pull out URL properties.
With webbrowser.Document you can get to any HTML element, whether it is statically or dynamically created.
What you can't get to through webbrower.Document is data that is loaded asynchronously using XMLHttpRequest(), because this data is not part of the browser Document Object Model. Web pages with scripted false buttons will be difficult to intercept.
However, if you know where the data is stored by the JavaScript executing on the page, you may be able to access it using webbrowser.Document.InvokeScript(). If the JavaScript on the page stores URLs in a mydata property of the window object, for example, you could try webbrowser.Document.InvokeScript("window.mydata") or some variation to retrieve the value of mydata into the C# app.
I am working on a website & it required to show a counter on home page.So I used an asp label as a counter that counts & display the DB records (i.e. 180000).It is working perfectly alright.
Now problem is that.I want to make it embed able
I want to embed that label to other websites.
e.g : <EMBED SRC="http://www.XXXX.com/graphics/sounds/18.mid" HEIGHT=60 WIDTH=144>
It should be dynamic (Counter Changes on home page should reflect where this counter has been embedded i.e. on blogs or on forums ) .
How can I do this?
Also what would be the best approach,a simple embed code, a iframe or through Java Script?
Thanks
There are lots of ways to do this. Without more information, it's hard to recommend an exact method. If all you want to do is display a number in html, then you can simply create an aspx page that writes the number and then let people iframe to it.
If you want to get more dynamic, you can create a generic ashx handler, or set up a web service that displays that information for you.
I am looking for a solution that will allow me to print generic url for a set of pages.
Example:
For pages - site.com/About/Contact.aspx, site.com/About/WhoWeAre.aspx, site.com/About/Members.aspx etc., user should see only site.com/About/ in the address bar.
Is that something achievable? This site is not SEO friendly and requires users to login before accessing content, also I don't expect site.com/About/ or any internal pages to resolve to any page when typed directly on browser. I am also fine if real url is printed on status bar if the user hovers on the internal links. I don't think URL Rewrite or URL Routing works here. Or may be I am missing something. Using .NET 3.5 and C#.
I am tagging sitecore because I am more interested in sitecore based solution where I have different nodes under About tree and I want users to see only upto /About in the address bar, but I think if it can be done in asp.net, I can figure out sitecore part.
As you are interested in sitecore, I can tell you how we have done custom URL in a recent sitecore build.
You need to have a custom link manager by extending the current LinkProvider.LinkBuilder sitecore class. Then you need to add your custom logic on how you would like the URL by overriding GetItemUrl and BuidlItemUrl to display URL and finally and it in the web.config for sitecore to use your custom link manager.
Absolutely, use the asp.net 4 routing engine.
This will give you exactly what you want:
http://weblogs.asp.net/dotnetstories/archive/2011/01/03/routing-in-asp-net-4-0-web-forms.aspx
EDIT: for 3.5 check out:
Friendly URLs for ASP.NET
The only way to solve this, keeping /About in the address bar, would be to create client-side code that switches out the content based on user selection.
You can do that by loading the About page and then load the content for any child pages using a postback or using ajax calls.
You could also put an iframe on the /About page, and have the navigation links point the iframe to the other pages.
I think you might be able to use the target attribute to target the iframe, or use javascript to change the src of the iframe.
I have a print function using JavaScript that prints just the contents of the iFrame and not the page the iFrame is in. What I want to do is have a DIV or something in the page being access through the iFrame that will go visible when you print and have a legend on it and then it will go back to invisible once the page is printed? Any help on how to do this? I am not the most adept at using JavaScript but will try it.
Thanks,
Forget the JavaScript. Trying to fiddle the page around a print from script is complicated, fragile and pointless. This is what a print stylesheet is for!
Add a stylesheet with media="print" which contains display: rules to hide all the parts of the part you don't want printed, and cause normally-hidden parts of the page to appear when being viewed on a printer. You don't even need a scripted print button, the normal web browser Print function will pick up the differences.
The IFrame Javascript element has a document property, which works identically to the normal page's document property.
That being said, if your IFrame's framed page is on a different domain from your framing page, you are probably out of luck. Browsers limit what one site can do to another site to prevent cross-site scripting attacks, and these limits will prevent you from accessing the framed page's document (unless it's on the same domain or you setup a cross-site file on the framed page's server).
I used to implement this above title by using iframe but now I dont want to use it any more I have some plans in my mind I need to implement them by opening an external page inside our asp.net page without using any iframe I have only simple aspx page with div tage and panel and some other serverside componants, I just want to know how I can do it without iframe ? I don't want to design new complex control but I am looking for some methods can do that for me.
I have to mention that I need to control area which is loaded by external site as the same as iframe but the difference is that iframe can not handled by ajax even you put iframe inside the update panel your page has refresh and postback while you are changing the src value programmatically (in c# code) so we have to design some others methods what is the solution ?
I thought I can make request an get some html and show into div but I couldn't to implement it.
You could
Make a WebRequest on the server-side and then set the div's text to HTML returned
You could make an invisible iFrame to make the request and then use JavaScript to grab the HTML from the iFrame and put it in a DIV. (EDIT: Comment suggests this won't work)
You can't generally make calls (like XmlHttpRequest) to external websites because of cross-site scripting issues.
Your direct request, "opening an external page inside our asp.net page without using any iframe" is not possible, by design.
You mention AJAX. You can use AJAX to load your page, remove the headers (or do that serverside) and replace the <body> tag with a <div> tag (or do that server side too). This way, you can place the contents of your page anywhere you like. As a container, I suggest you use a block level element, a <div> would suffice.
The only (!) problem here is: cross-site requests like this are not honored by browsers. You can solve this server-side by loading the page from elsewhere using WebRequest or similar means.
Depends on where you'd like to merge the data. If you'd like to merge the data on the client browser, your only other option besides frames is to use Javascript/Ajax.
You can do a jQuery.ajax() on page load and use the html() method on a div to populate it with the textual result of that AJAX call.
Try to use as little of the WebForms control hierarchy and life-cycle as possible. It sounds like your problem can be fixed with AJAX if you don't mind the second request on page load.
If you would like to merge the content on the server side ( rarely the right thing to do ) you can use System.Net.HttpWebRequest to get and merge the data before returning it to the browser.
there's no substitute for an iframe in your situation. you're not going to be able to make ajax requests to the other site due to security concerns. you could retrieve the contents of a single page server side and render it to the client but none of the functionality will be included, since the content is now running in the context of your own site.