XUL iframe firefox addon, how to change the src within the iframe? - javascript

I am developing a firefox addon,
in my settings page dialog.xul i have an iframe where i load different settings pages page1.xul page2.xul page3.xul
Iframe :
<vbox flex="1">
<iframe
id="iframe"
src="chrome://xxx/content/page1.xul"
flex="1"></iframe>
</vbox>
Within the iframe i need to navigate from page2.xul to page3.xul
with the code in page2.xul
My code (page2.xul) :
gBrowser.loadURI("chrome://xxx/content/page3.xul");
Also tried
document.getElementById("iframe").setAttribute("src", "chrome://xxx/content/page3.xul");
but it's not working i know iframe container is not accessible from the iframe but how can i do that redirection ?

With iframe in XUL you must create it with the HTML namespace otherwise things like load events don't work right, see this topic: http://forums.mozillazine.org/viewtopic.php?f=19&t=2809781&hilit=+iframe
Once you do that, changing src etc should work as expected.

Solution :
I managed to handle the code in the main XUL
Apparently XUL does not support the structure
[XUL1 >> iframe(XUL2 : change something in XUL1)]
This structure is not supported in classic HTML + Javascript for security reason
and it's also the case in XUL

Related

Setting iframe src via JS isnt working specifically for sharepoint

Setting src directly in iframe is working as expected
I'm trying to embed a Sharepoint document here.
For eg
<iframe src="https://rocketlane123-my.sharepoint.com/personal/lokeshkannan_rocketlane123_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc={8822527b-0c56-44f9-8263-40c737db903c}&action=embedview"
width="476px"
height="288px" />
Whereas when I set the src in the script it's failing
<iframe id="x" width="476px" height="288px"></iframe>
<script>
document.getElementById('x').src = "https://rocketlane123-my.sharepoint.com/personal/lokeshkannan_rocketlane123_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc={8822527b-0c56-44f9-8263-40c737db903c}&action=embedview";
</script>
This happens explicitly with SharePoint. So I would like to understand a couple of things here.
1. Am I doing something wrong?
2. Is there any CSP headers which block the parent from adding via JS?
3. Is there any official way from SharePoint to allow this?
3. Is there any way to hack this?
Thanks in advance.
Since this happens across chrome, safari and firefox I think it's not a bug in a specific browser.
Trying this in Firefox yields this error message:
To protect your security, login.microsoftonline.com will not allow
Firefox to display the page if another site has embedded it. To see
this page, you need to open it in a new window.
Opening the console gives this message:
The loading of [url] in a frame is denied by “X-Frame-Options“
directive set to “DENY“.
This is a header that's set by login.microsoft.com to disable embedding the link as an iframe.
This link details this design choice: https://learn.microsoft.com/en-us/sharepoint/troubleshoot/sites/cannot-display-sharepoint-pages-in-iframe
The link mentions you can override the behavior by setting 'AllowFraming', though it doesn't recommend it, as there may be site-breaking changes by embedding it.
A guide to use this feature can be found at this link
The problem is in, javascript amp; should not represent as &.
Change your link to
<body>
<iframe id="x" width="476px" height="288px"></iframe>
<script>
document.getElementById('x').src = "https://rocketlane123.sharepoint.com/sites/MyDocsforSP/_layouts/15/Doc.aspx?sourcedoc={6d327004-5d52-4e42-9707-c964631f8e65}&action=embedview";
</script>
</body>

PDF in iFrame getting downloaded instead of displaying [duplicate]

I want to open the pdf file in an iframe. I am using following code:
<a class="iframeLink" href="https://something.com/HTC_One_XL_User_Guide.pdf"> User guide </a>
It is opening fine in Firefox, but it is not opening in IE8.
Does anyone know how to make it work also for IE ?
Using an iframe to "render" a PDF will not work on all browsers; it depends on how the browser handles PDF files. Some browsers (such as Firefox and Chrome) have a built-in PDF rendered which allows them to display the PDF inline where as some older browsers (perhaps older versions of IE attempt to download the file instead).
Instead, I recommend checking out PDFObject which is a Javascript library to embed PDFs in HTML files. It handles browser compatibility pretty well and will most likely work on IE8.
In your HTML, you could set up a div to display the PDFs:
<div id="pdfRenderer"></div>
Then, you can have Javascript code to embed a PDF in that div:
var pdf = new PDFObject({
url: "https://something.com/HTC_One_XL_User_Guide.pdf",
id: "pdfRendered",
pdfOpenParams: {
view: "FitH"
}
}).embed("pdfRenderer");
This is the code to link an HTTP(S) accessible PDF from an <iframe>:
<iframe src="https://research.google.com/pubs/archive/44678.pdf"
width="800" height="600">
Fiddle: http://jsfiddle.net/cEuZ3/1545/
EDIT: and you can use Javascript, from the <a> tag (onclick event) to set iFrame' SRC attribute at run-time...
EDIT 2: Apparently, it is a bug (but there are workarounds):
PDF files do not open in Internet Explorer with Adobe Reader 10.0 - users get an empty gray screen. How can I fix this for my users?
It also important to make sure that the web server sends the file with Content-Disposition = inline.
this might not be the case if you are reading the file yourself and send it's content to the browser:
in php it will look like this...
...headers...
header("Content-Disposition: inline; filename=doc.pdf");
...headers...
readfile('localfilepath.pdf')
The direct PDF didn't work on Mobile phones and it doesn't support responsive UI.
Here is the best solution.
https://stackoverflow.com/a/66548544/2078462
Do it like this: Remember to close iframe tag.
<iframe src="http://samplepdf.com/sample.pdf" width="800" height="600"></iframe>

iframe accessing child JavaScript of source

I have been trying to access a html source file through iframe. It works fine and I can see the source, but my external JavaScript file doesn't work through the iframe.
So far this is what I have for accessing the HTML file.
<iframe src="Example.html">
<p>Your browser does not support iframes.</p>
</iframe>
and then in Example.html I have:
<script src="SpinScript.js"></script>
This works if I run the HTML file in any browser, but not through the iframe
In this HTML file I have other JavaScript elements but they are just written in this document and they work fine through the iframe.
What I'm wondering is if have to re-establish where the JavaScript file is in the iframe?
Hope that all makes sense and thanks for your time.
Your parent window and iframe should be from the same source (url),
then you can use
window.frames[framename] to get window object in iframe

JQuery is not loading in an iframe in IE7?

I have two different web applications in different domains. in web app1, i have an iframe and its src refers a page which is in web app2.The page which needs to be loaded in an iframe has some JQuery.But the problem is it is not loading in an iframe. But if i access the same page in the same web app2 then it is working fine. It works fine in Fire fox and the issue is only with IE. am using IE7.
I have below code in the page which needs to be rendered in an iframe.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" ></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.js"></script>
Am i doing anything wrong here? Please help me!
Thanks!
IE can have issues with security when using IFrames.
Try setting your security mode to lowest for that site and see if it works (Making sure to set it back after testing to ensure your browser isn't left vulnerable!). If it does, change the code in the iframe to load the javascript from the same domain instead of the CDN. (or just try this first!)
It is possible that IE is preventing the content of the iframe from loading the JS from a seperate domain. You can check this using something like fiddler, see what calls the page makes after loading.

Javascript/Html: Load Html into FrameSet with onunload event

Explanation of problem in full below, you could probably just skip to the code at the bottom if you want.
What happened is a impatient client wanted his swf banners converted to html5 without having to actually code them from scratch. So i utilized Google's new tool, Swiffy. I then tried to place this new generated html5 page in the header of the clients wordpress site. I have gotten it to load as an iframe but the problem that I am encountering is when you click on a link on the loaded html5 page, it just loads the linked page in the iframe, not the parent page/window (which is to be expected). I tried a bunch of other methods, and tried changing the AS2 links in the .fla as well but no luck. I am guessing Swiffy can not read every AS2 code, and so it has been ignoring my "_blank", "_parent" when I use getURL. Anyway, I have been trying to get it so when the iframe unloads to go to the linked page, it uses Java to just open the link on the parent page. But iframes cant use the onunload event, but I am pretty sure framesets can. So this is the code I was trying and it doesnt work.
<frameset rows="100%" onunload="window.open('http://www.goaefis.com/about-aefis/what-is-aefis/','_parent');">
<frame src="www.goaefis.com/banner_Test.html" frameborder="0" scrolling="no" />
</frameset>
Any help will be super appreciated.
try to use the "target" on your frames.
Here's a example:
http://www.w3.org/TR/html4/present/frames.html

Categories