Page reloading and malformed HTML problems in a XULRunner based app - javascript

I am writing an application on XULRunner that displays HTML pages from the web:
I have a very simple XUL file with a in which is just a filling the window and loading a local HTML file.
In my HTML, I have an iframe to load content.
What's cool with XULRunner is that I can access the content of the iframe for many things (display page title, images...)
What's not cool at all is that, unlike what I had when my app was running in a browser, I have two big bugs with some pages:
1) Some (many?) pages (like "yahoo.fr" have malformed HTML content, especially for tag where the tag is not closed (the IMG tag without the /> at the end).
==> This does not bother Firefox but in my app, XULRunner does not decode the HTML and thus display the rough HTML source code in the page.
2) On some pages, like, for now, the home of nytimes.com, the login page of bloglines.com and of yahoo.fr, "something" happens in the iframe that causes the src of my tag (that is my app that SHOULD NEVER CHANGE) to change thus closing my app.
==> I guess it may be linked to an attempt to open in another window.
Does anyone have a clue to solve these two problems? Better version of XULRunner (I am using 1.9.1)? XUL options to prevent a page to open in new window? Others?
Thanks for your help,
J.

Rather than a <iframe/>, use a <browser type="content-primary"/>. That will solve your second problem (by letting the system know that the contents of that frame belongs to the web and shouldn't be able to change you).
The first question really depends on how things are being loaded. Are they from http, or from a previously-saved local file? Do you useful mime types and things from the server? Or, if local, what file extension do you end up with?

Related

How to access local html files on sdcard directly via iframe in a WebView using Java

I am a beginner to Android App Development. I am creating a Code Editor app (that would allow developers to edit and run their html files) by using Java along with html, css and javascript (via WebView). I could easily accomplish the edit part but the problem is with executing any html file.
My first try was to use iframe with a src pointing directly to the file in sdcard-
<iframe src="file:///storage/emulated/0/<file-name>.html"></iframe>
But with this code, the problem is that the app immediately crashes when this iframe loads. Not only iframes any kind of request sent to a route in sdcard from the webview immediately crashes the app.
I find various solutions on internet but they all just add a JavascriptInterface that can be used to display images on webview. But that's not the case with me as you know the code that I want to execute is dynamic
and must be able to access any kind of file that is accessible to a html file in a normal browser and also that the entire sdcard, though can be referenced in html codes, cannot be copied to assets folder. With these circumstances, all answers on internet are no helpful for me.
Summary- I want to view the output of any html code, stored in sdcard of users, in such a way that the output appears similar to what it would in a browser, that is by using Java and WebView Please help.
Edit-
I want the solution to be by use of a iframe, which can be completely accessible to entire WebView.

How do I create a Local html file to open webpage and inject a JavaScript function

I have a legacy web application that we are not allowed to modify yet. We need to add a new function to the application in the short term. We have been told that we may modify the webpage with any local scripts we want but we have to wait 4 months before they will unlock the application.
So my goal is to create a webpage locally, click on that local html file and have it open the url for the legacy application, and then inject the new JavaScript function to the application.
On "your" page, use an iFrame to "import" the page you cannot edit, on your page add whatever modifications you need/want.
If there is no server side scripting on the page, then copy the page source to your page, and add whatever you want to it. It is difficult to give you a focused answer without having access to or more information about the actual legacy page.
It can't be done directly since browsers prevent cross site scripting so injecting js from local machine will complain with same origin errors the only workaround i know is to use developer tools and open console then you can type your JavaScript there and run it directly

Bookmarklet in Phonegap or iframe that acts as top window?

I am building an app for my school in HTML and using the Github + Phonegap cloud builder to package it as .apk, .app, etc for cross platformity.
The app its self loads an external webpage. This webpage is the schools and I have permission from them to access it but I do not have access to the server its self. I wrote a bookmarklet that accomplishes the tasks I want the app to accomplish however this requires the ability to run the bookmarklet. This can be done in any standard web browser but I can't seem to figure out how to do it in Phonegap.
My first thought was to iFrame the schools's site but sadly they use every possible breakout code that even after implementing every fix I could find it still navigates the top window and not just the iFrame.
I come to you asking for help.
Is there a way to do either (or both) of the two tasks below?
Create an iFrame that, to the page it loads, appears and functions exactly as the top window so that even when it navigates top the top window it still stays within the iFrame
Run a javascript bookmarklet from a phonegap app without the need to involve any native code so that when this external page is loaded, additional local JS can be executed without being called by the page its self
You can set src of <content> in config.xml file to be a remote url. (which by default points to local index.html in www directory)
<content src="REMOTE_URL" />
see The config.xml file.

Can't open .PDF or .DOC(X) in iFrame

I'm developing an iPhone app using PhoneGap, Xcode, HTML and JavaScript. I have an iFrame that should view documents (right now I am using a test document instead of allowing the user to choose - that's coming later) that have been downloaded (again, i chose the document). I tried using a .pdf file and a .docx file which are both supported by iPhone, but clicking the button I coded opens them in Safari instead of the iFrame. Here's the code to view the document (JavaScript and HTML);
function viewOnline() {
var site = "file://" + pathToRoot + "/editme.txt"
$('#myIframe').attr('src', site);
}
<button onclick="viewOnline();">View Online</button></li>
<iframe id="myIframe" style="width: 210; height: 210px;" seamless="seamless" src=""></iframe>
Is it just not possible to view .pdf etc files in iFrame or is there something wrong with my code?
** pathToRoot is coded (and tested to be correct) elsewhere in the application - so i don't need to hard-code the file path, which will change when i transfer it to the device instead of the simulator.
** if you need the code where i download the file, then i can give you it - just comment below
** I'm also fairly new to working with Xcode and PhoneGap so if i need to alter something with them if you could give as much detail as possible that would be great - Thanks so much in advance
Edit
I know about the OpenWhitelistURLsInWebView, and have enabled it and allowed the website i'm downloading from in the ExternalHosts array - but it still won't work.
It's not possible. Most of the mobile browsers doesn't come preloaded with Adobe plugins and all. It's not a desktop you see. Its a mobile. So it's not possible unless you create a own browser and include the adobe plugin(meaning you have to write pdf rendition logic because the plugin wont work in mobile).
iFrames are very rarely needed and are often employed for wrong reasons. Often you can achieve the exact same thing you are going for using normal styles and simpler markup.
Also, googling phonegap/cordova iframe gives many results that spell out trouble with iFrames. For the official implications guide on them see iFrame Usage.
In your case these are the things you need to consider:
Enabling iFrames on PhoneGap-iOS requires that you whitelist the
iframe domains and enable "OpenAllWhitelistURLsInWebView". While this
doesn't sound like a problem, many applications want to open specific
sites in MobileSafari (not a ChildBrowser), which cannot be
accomplished easily when "OpenAllWhitelistURLsInWebView" is enabled.
To change OpenAllWhitelistURLsInWebView open the Cordova.plist file in
Xcode.
To whitelist a domain. Add it to the ExternalHosts array in the
Cordova.plist file. Simply press the + next to the ExternalHosts title
and when the item0 appears bellow add your domain to the value section
(in the format example.com).

Looking for a javascript that will force/redirect child page into iframe found in parent page

im new here new in programming. I hope you can help me :)
I am using Iframe for a project. Ive read about Iframes and I know its not the best choice.
Unfortunately I cant find another replacement for it and make it work the way I wish.
Here is my problem:
I have an index.html page, which holds a main Iframe. I have external links on same server, e.g page1.html page2.html page3.html.... what need is, prevent direct access to e.g page1 through search engines and load page1 content into index.html iframe.
I came across many scripts, redirecting to index.html and load child page into Iframe, the issue is about its ugly url link in the browser. e.g
""domainname/index.html?domainname/page1.html""
This bothers me because I need to access pages with simple url like e.g "domainname/page1" but if a user type it and click "go" it will convert to ""domainname/index.html?domainname/page1.html""
I found another choice, but I dont know how to implement it the way i need it, i.e access sub-domains with simple slash (domainname/content) here it the link:
http://www.hashbangcode.com/blog/using-jquery-load-content-page-without-iframe-536.html
Have you considered using a robots.txt file to instruct the search engine crawlers to ignore the pages? Saves you a lot of trouble and lets you build the site without such contrivances.
Have you checked out using robots.txt? This could be used to prevent browsers to avoid pages you do not wish to appear in search results.

Categories