I am building a website and there is an embed iframe on the page. I found that when users drop a pdf file over the iframe. The browser will close my website and load the pdf. How can I stop browser rendering the pdf file? I know the drop event I can use but this case happens in the iframe. Is there a way for me to handle drop over iframe? My iframe is loading a url which is not the same origin as the parent window.
I don't have control on the iframe I am embedded. What I want is if the iframe doesn't handle drop event then I disable the drop otherwise let iframe to handle it.
This isn't specific to an iframe, it just is what browsers do when you drag a pdf onto them - or most other files they can open, as far as I know. I wouldn't worry about it. If it's fine for every other site, it's probably fine on yours. If a user has complained, just explain it's the browser and there is nothing you can do.
People might try and find hacky ways to disable it, but my recommendation is not to.
Related
does anybody know how can I expand javascript so that it targets whole website not only the page in iframe it is on. Im currently using a javascript for gallery on my website, so when you click on a picture it pops up enlarged, however since the page with javascript is in an iframe it shows only in the iframe, how can I accomplish the pop up to expand to the whole page?
Thanks in advance.
Iframes can call out to the window which embeds them using simple javascript (see window.frames on http://www.w3schools.com/jsref/prop_win_frames.asp). However, if src of the iframe is on a different domain, then the script can only affect the iframe, due to security policy within the browser.
If you'd like to apply a work-around, there are some solutions like this: Yet Another cross-domain iframe resize Q&A
These solutions tend to break on different browsers and with updates to browsers.
Your best bet is keeping the entire iframe contents within the browser by writing the iframe code yourself (and hosting on your own domain).
I need to create a chrome extension that for every web page te he user opens - he will have a button on top of the page (similar to the google translate extension - just that it will appear with page load, without the need to press a button) - preessing on it will do some activity.
from what i saw - the way to do it is to create a content script that will add an iframe that includes the button on the window.onload. just before i do that - i want to be sure there is no more simple way of doing that.
Thanks.
There is an experimental infobar API, but it's unknown when, if ever, it becomes stable.
As-is, you really need to inject your UI into the page DOM from a content script, with an iframe being a good solution to separate your UI from the page.
If it's just a button for each page then you could use a Browser Action
If you'd like for it to actually be in the page then an iframe is a good way to go.
I'm building a social bookmarking application for use within large companies.
It has a simple JavaScript bookmarklet which currently works fine - the bookmarklet allowes users to save a bookmark from popular browsers. It works for public web links quite well - and is fairly browser-agnostic. The closest example of such a bookmarklet is this:
http://delicious.com/help/bookmarklets
When I am viewing a PDF in my browser (let's say Chrome/Mac):
http://website.com/file.pdf
This does not work of course - since there is no way to inject HTML markup on top of a PDF being viewed in-browser.
What is the best approach to making links to non-http resources work within a bookmarklet? Do I have to create then inject some kind of invisible iframe and then grab a parent frame and it's URL to be able to save it?
I don't know about all browsers, but in Firefox you can inject Javascript and iFrames over PDF files and images. This is because images and PDF files are actually displayed inside special dummy HTML pages generated by Firefox. I think Chrome may be the same.
You can see this for yourself by opening a PDF or image and then opening the Web Console (must use menu, can not use CTRL+SHIFT+K in this case) to get the JS console and then type document.documentElement.outerHTML to see the actual dummy HTML where the PDF or image is embedded.
To detect situations where I can not add an iFrame or other HTML to a page, I might test if document.documentElement is defined, or possibly some other DOM element.
For any browser or file-type combination where this will not work, or if I just wanted to keep things more simple, I'd open a page on my server in a new tab or window and pass the page title and location to that page like http://mysocialsite.tld/add-bookmark?title=file.pdf&location=http://anothersite.tld/file.pdf. That page on my server would let the user complete the bookmarking process.
In my website I use an iframe to show an external content but there is a popup window in it.
I can/do block popups in my site but not inside the iframe, is there a way to disable a specific (or all) javascript from an iframe?
There is an Internet Explorer specific way to disable scripts in a frame, but nothing general.
You really should negotiate with the owner of the document that you are reusing.
I'm using Google search in a page, and it shows up in an IFRAME. However, when you click on a link in the search, it's leaving my site and redirecting to that other site. Is there a way to intercept that call with jQuery and make it open that link in a new window, instead?
Due to security reasons, what you can do with an iframe is very limited (In cases where you frame another domain).
The way this is implemented varies a bit from browser to browsers but most browsers won't let you manipulate the data in the iframe.
To my knowledge this isn't possible, assuming you are refering to an implementation of http://www.google.com/cse/