I'm opening some webiste by simply using:
window.location.href = "https://someaddress";
in my neutralino app.
How can I access html (dom) of the viewed page and interact with it?
Is it possible in neutralino.js?
You can access the DOM the same way you would in regular webpage.
For example: let myDivs = document.querySelectorAll("div") to select all div elements on the page.
Related
I'm struggling with some anchors / other html pages ( buttons on left) to be displayed in another div in the same page ( to be more exactly in the right ). Are there any solutions to this with div? Or maybe with frame/iframe, even jQuery any tips please?
Are there any solutions to this with div?
Fetch the content with JavaScript (e.g. XMLHttpRequest).
Strip out the bits you don't need (e.g. everything except the contents of the <body>
Use DOM manipulation to add it to the div
Or maybe with frame/iframe
That is exactly what iframes were designed for. Set the target attribute of the anchor to the name of the iframe
Loading content into a portion of a page comes with a lot of gotchas. At the very least it interferes with the ability of visitors to link to the content they are actually viewing (although you can use the History API and pushState to compensate for that). It is almost always a better idea to just link to a new page which includes (via a template) any content that is common to all the pages.
If the page links to a HTML page you can append an iframe using jQuery as follows:
$(document).ready(function(){
$('.button').click(function(){
// Prevent Default Action
event.preventDefault();
// get the href parameter
var url = $(this).attr('href');
// Append the iframe
$('#content').append('<iframe src="'+ url +'"></iframe>');
});
});
Here is a working Example
If you are able to return a JSON or XML response you can use $.ajax to get the response and then append it inside a div instead of an iframe.
I'm designing a Windows 8 Reader App, and I have to use a control to show the HTML content, which is fetched from some website feeds. Cause those HTML content may contains images or some other formatted text, now I'm using a richtextblock to show the HTML content, but it costs a lot of time to parse the HTML content.
So I'm wondering if there is any controls that can handle the HTML content except the WebView.
Thanks.
Updated:
The reason I can't use WebView is that I need to implement pagination, like the image belowed:
As JP Alioto mentioned you should use the WebView control.
You can use the NavigateToString method to load the HTML. Or use Navigate to request a URI.
There are issues however with using the WebView control, specifically it is rendered differently and is not a standard control, this means things like your app bar or settings pane will not render on top of the WebView, there is a workaround by using the WebViewBrush to "paint" the WebView to standard control such as a rectangle when needed.
Also you can make a screenshot of the webpage you want to display. But to make a screenshot of webpage it's also not easy to do, but I offer you to make it with some special sites wich are created to take screenshot of other websites. Then you can download an image this sites return and open and display it in your windows 8 app. I show You some example how to I did that:
StorageFolder screens = await Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFolderAsync(#"Screens\" + folderName, CreationCollisionOption.GenerateUniqueName);
var downloader = new BackgroundDownloader();
IStorageFile file = await screens.CreateFileAsync(fname, CreationCollisionOption.GenerateUniqueName);
string my_uri = "http://api.snapito.com/web/e3c351d5994134eb1aea855ce78e296c3292d48a/lc/" + url + "?type=jpeg";
DownloadOperation download = downloader.CreateDownload(new System.Uri(my_uri), file);
await download.StartAsync();
I think there are only two options but none of them are really good:
Use WebView and transform your HTML with CSS and other techniques to look native. Use the ScriptNotify and NavigationStarting and other events to navigate to another page. In W8.1 the WebView is much better (eg. treated as regular control not floating over all other controls,...)
Parse your HTML and generate native elements. I started such an implementation and created a XAML control to display HTML with native controls (see https://mytoolkit.codeplex.com/wikipage?title=HtmlTextBlock). However if you have complex HTML (eg iframes, etc.) this may not work and you have no other choice than to use the WebView control.
I need to get the id of a div in the parent document of an iframed document. The actual scenario is I have a facebook application developed using FBML. The canvas page contains an iframe. If the user clicks on a button inside the iframed document, I need to display a div in the canvas page that is hidden when loading.
Thanks in advance...
did you try parent.document.getElementById('YOUR_ID'); ?
Are both documents (parent and iframe) in the same domain? If no, then browser doesn't allow you to access to parent document for security reasons.
EDIT: If both documents are in the same domain then you can access the element of parent document as follows:
var parentDoc = parent.document;
var el = parentDoc.getElementById("foobar");
try $(this).parent().attr('id')
I have Silverlight application test page named A.html hosted in an iframe which is an element of B.html, so is there a way for Silverlight app to access elements in B.html by referring something like HtmlPage.Document..?
Thanks!
You can always walk up the DOM tree by doing something like this:
var htmlElement = HtmlPage.Document.DocumentElement.Parent;
In the container html page, add following function:
function GetParent
{
return parent;
}
In the SL control, do this:
HtmlWindow parent = (HtmlWindow)HtmlPage.Window.Invoke("GetParentWindow");
Now to invoke any function from the parent Html page, just call
parent.Invoke("myFunction");
Hope this solves your issue.
Ahmad.
Using Silverlight/Moonlight is very risky. Most of your website's guests will not have this plugin installed. This will strongly limit your website accessibility.
Use Flash instead, or even better use only [x]html+css+javascript.
I want to display an HTML formatted content in my application preferably inside a Web Browser control.
I could create an HTML document first and then load it in the Web Browser control, but that is just too clumsy.
Is there any way I can load a string that contains HTML code directly into the Web Browser?
String = "<b>Hello</b> World"
Expected output: Hello World
I'm using Visual Basic 9 (VS2008).
You can do this by dragging a WebBrowser control onto your application and then adding the following code:
webBrowser1.DocumentText = "<b>Hello</b> World";
You can open the document object in the Web Browser control then:-
document.write("<b>Hello</b> World");