I have a file
file:///C:/Users/7%20Legged%20Spider/Desktop/test.html
When I set it into an iframe
< iframe src="file:///C:/Users/7%20Legged%20Spider/Desktop/test.html">
The iframe is blank, why is this and how can I fix it
It is because of security issue. You can not bypass it by any mean.
You should not use local file as href because of:
Security problems
"Unexpected" URLs (not everyone has C:\)
If you are using it only for development, you may want to upload the file to your server in order to include it.
Related
I'd like to show the content of both a txt and a pdf file and embed these into a webpage.
The files are located on a webserver with a different domain.
How can I include those? Is the only change using an iframe? Or could I also use the embed or different tags? If yes, how?
<iframe ng-src="{{some.url.text.or.pdf}}"></iframe>
There are several issues you may encounter:
Angular will deny you setting ng-src out of your domain by default. To overcome this use $sce.trustAsResourceUrl as described here - How to embed an external file in a webpage with angularjs?
Any external url you refer, may still deny embedding it by having X-Frame-Options: SAMEORIGIN set in the response headers and you can't do anything about it. The browser will deny embedding if such headers are present.
Not every document type can be embedded and the support depends heavily of the browser and it's plugins.
When it comes to embedding anything in iframe, the problem is that you cannot get the size of the content if it's not from the same origin. Making it impossible to calculate proper iframe size. Thus usually ending up in bad user experience. So before embedding any document, consider if user is better off having it as a download or in a separate window.
For a PDF specific solution without iframe/embed check out this post - Recommended way to embed PDF in HTML?
not complete but something like
<iframe iframe-set-dimentions-onload width="90%" my-frame="fullyLoaded()" ng-attr-srcdoc="{{htmlResponse}}" id="iFrame">
.directive('iframeSetDimentionsOnload', [function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
element.on('load', function(){
if(window.localStorage.getItem("iFrameHeight")==="present")
iFrameHeight = element[0].contentWindow.document.body.scrollHeight+125 + 'px';
else
iFrameHeight= element[0].contentWindow.document.body.scrollHeight+'px';
element.css('height', iFrameHeight);
});
}
}}])
do whatever u want after loading at $scope.fullyLoaded()
The files are located on a webserver with a different domain
If it's a cors issue , then it's a different case
I'm migrating project from MFC to Qt now, and it's using embedded web browser, which displays local (resource) html-page. Local page is displayed fine, no problems. But i have a problem to set html content to child tag. QWebView can't display external images set via javascript $("#").html() - only text and local (resource) images are displayed. In MFC version with IE webview the same script works fine.
I've tried to use QWebElement::setInnerXml, but result is the same: only local content is displayed.
After that i've tried to use QWebFrame::setHtml, but after call app crashes somewhere in QWebPuginDatabase::searchPathes, despite that i'm calling QWebFrame::setHtml from main thread.
Did anyone meet the same problem? Has anyone solution to resolve my problem?
Thank you
You may need to change a setting, try:
QWebSettings::globalSettings()->setAttribute(
QWebSettings::LocalContentCanAccessRemoteUrls, true);
The QWebSettings documentation describes the attribute as (emphasis mine):
Specifies whether locally loaded documents are allowed to access remote urls. This is disabled by default. For more information about security origins and local vs. remote content see QWebSecurityOrigin.
I'm building a local html file to show dynamically some data from an XML file and by using Chrome's Inspector I figured my XML file is not being parsed because it is "not hosted on a webserver"
XMLHttpRequest cannot load data.xml. Cross origin requests are only supported for HTTP.
I know that there are a few flags I could pass to Chrome/web browser to workaround this limitation but I'm looking into some alternative method. I will probably have to distribute this files to a few people and teaching them how to pass flags to the browser is not an option for me. Hosting them on a web server is not an option either.
Thanks a lot in advance.
No ghost unless you set up a local server or host the XML file locally. Ajax has to follow the same origin policy.
If you're willing to use a library you can use jQuery's AJAX method to perform a cross-domain request (i'm not entirely certain that jQuery will support what you're trying to do). JSONP works, but you have XML data...
You could try loading it in a script tag anyway and see if you can get the innerHTML value without breaking the script; once you're done getting the text from it, remove the script from the page. You may be able to get at the data before the browser tries to parse the script by attaching onload and onreadystatechange events to the script element.
var s = document.createElement('script');
s.src = '/path/to/file.xml';
s.onload = s.onreadystatechange = getData;
function getData(e)
{
//get the text out of the script element
//remove the event handler from the script element
//remove the script from the page
}
document.getElementsByTagName('body')[0].appendChild(s);
I didn't test it, but it might work.
How about setting up a local webserver? XAMPP should be easy to install even for novice. Just tell them to put your files in the htdocs folder, run xampp and start the apache server.
Unless there's a compelling reason to have a separate html and xml file, you could just put the data directly in the html file.
I'm afraid if chrome only provides options that you don't like to apply, your application and chrome will not come together. Access via iframe & object does'nt work too, load()-method of createDocument is not supported by chrome(if it does I guess you got the same error).
Whatever you try will be a sideway to pass chrome's restrictions, what cannot be good, because I think they have good reasons to setup these restrictions.
I'm testing a flash script that calls a JavaScript function (both, the swf and the HTML file are local). The flash movie is not allowed to access the HTML file that contains the js-function.
I've learned that I have to put both files into a security sandbox, so I added the path to both files (HTML+swf) to a file test.cfg in C:\WINDOWS\system32\Macromed\Flash\FlashPlayerTrust.
But still the same problem. What to do?
thanks!
The requirement for calling from Flash to JS is that you have the allowScriptAccess parmeter set in your embedding code of your HTML document. Iirc, you can specify always or sameDomain and it will work. The second option obviously require the swf to be coming from the same domain.
I don't know which title I should use for this question.
I have a webpage (e.g. index.html) which contains flash content, url:
http://www.abc.com/travel/sg/traffic/
After I finish the webpage and upload onto the staging server, the customers said that they may need to use different domain to go to the site, e.g.
http://sg.travel.com/
The images or hyperlink do not work because of this. To handle this, I try to use the base tag as follows:
<base href="http://www.abc.com/travel/sg/traffic/" />
The images and hyperlink work. However, flash file cannot call javascript afterwards.
I would like to know how I can fix the problem.
Thanks.
Are you using relative links in the flash file? Try passing the url as a parameter and prepend the links in the flash file with them. You may also need to set up a proper crossdomain.xml to allow your flash to access other domains.
if images are the same domain as the swf, you can use relative paths.
try with
"/images/foo.png" instead of "http://www.abc.com/travel/sg/traffic/images/foo.png"