How to prevent an iframe from stealing drop event from parent container?
You're going to have to disable mouse events on the iframe. You can stop them from happenning with pointer-events: none
which is pretty supported: https://caniuse.com/#feat=pointer-events
I forked your demo to show you: https://codepen.io/anon/pen/dmPRqg?page=1&
I didn't wire up anything to actually toggle the mouse events, you can do that via a class or directly to the style or any other several ways.
Prevent iFrame from getting focus when its src has an id
The sandbox attribute solved my problem
Prevent iframe stealing
With JavaScript you can do
if(window.top==window){
//not inside iframe
} else {
if(parent.parent.someFunction){
parent.parent.someFunction();
} else {
alert("framing is not allowed")
}
}
ORif (window.top !== window.self) window.top.location.replace(window.self.location.href);
Some modern browsers also support the X-FRAME-OPTIONS header, that can have two values:* DENY – prevents the page from being rendered if it is contained in a frame
* SAMEORIGIN – same as above, unless the page belongs to the same domain as the top-level frameset holder.
Browsers that support the header:* IE8 and IE9
* Opera 10.50
* Safari 4
* Chrome 4.1.249.1042
* Firefox with NoScript
Remove focus from Iframe on page load
if assumed the iframe is not served from the same domain.. you can place any other focusable dom element after the iframe in the footer with autofocus
set as true
. And if that does not work please try the following in the parent main window:
$(window).on('load', function() {
setTimeout(function(){$("body").focus()}, 100);
};
OR going by vanilla JSwindow.onload = function() {
document.getElementById("some-focusable-element-from-parent-window").focus();
};
Prevent child iFrame to get focus
It depends upon what you're really trying to accomplish and which focus methods you are trying to prevent. There's no magic setting you can set that prevents focus going to an iframe.
You can put a transparent element over the top of the iframe and have it capture all clicks so nothing in the iframe is clickable. You can likely just position this with CSS and wouldn't necessarily need javascript unless the iframe size is dynamic or not known in advance. This won't prevent javascript code from setting focus to the iframe, but will prevent mouse clicks from moving the focus to the iframe.
You can regularly check (javascript polling) where focus is and if it's not in your own document, then put it back in your document. This is kind of a hack.
Prevent iframe from keeping focus using jquery
Your issue seems to be two-fold.
You are using
setTimeout
which will only run your callback once. I think you mean to usesetInterval
, which will repeatedly run the callback.You can't set focus to
document
using thefocus
method natively or in jQuery. In order to restore focus to thebody
, you should call theblur
method on the currently active element usingdocument.activeElement
.
function focusit(){
if(document.activeElement)
{
document.activeElement.blur();
}
}
setInterval(focusit, 100);
CodePen Demo Iframe stealing mouse events
Mouse events are tied to windows, iframes are windows. Its a miracle this works in webkit browsers as you say.
You need to pass the eventListener and perhaps eventHandler between your parent window and the iframes when the mouse moves into them.
Some reference about passing objects between iframes: http://www.dyn-web.com/tutorials/iframes/refs.php.
Related Topics
How to Remove Text Between Tags in PHP
Create a Joomla! Article Programmatically
Measure the Pronounceability of a Word
Possible to View PHP Code of a Website
Php: $_Server Variables: $_Server['Http_Host'] VS $_Server['Server_Name']
Which PHP Mcrypt Cipher Is Safest
How to Call Curl_Setopt with Curlopt_Httpheader Multiple Times to Set Multiple Headers
Difference Between Buffered and Unbuffered Queries
Disable Doctrine 2 Lazy Loading When Using Jms Serializer
Reverse Letters in Each Word of a String Without Using Native Splitting or Reversing Functions
Add Some Attribute Values to Woocommerce Variable Product Title from Chosen Variation
Why Doesn't PHP Permit Private Const
Using Moodle Create Users and Enroll Them in Courses via SQL
Jquery:: Ajax Powered Progress Bar
Error with .Htaccess and Mod_Rewrite