using postmessage to refresh iframe’s parent document

Use: window.parent.postMessage(‘Hello Parent Frame!’, ‘*’); Note the ‘*’ indicates “any origin”. You should replace this with the target origin if possible. In your parent frame you need: window.addEventListener(‘message’, receiveMessage, false); function receiveMessage(evt) { if (evt.origin === ‘http://my.iframe.org’) { alert(“got message: “+evt.data); } } Replace “my.iframe.org” with the origin of your iFrame. (You can skip the … Read more

Changing the child element’s CSS when the parent is hovered

Why not just use CSS? .parent:hover .child, .parent.hover .child { display: block; } and then add JS for IE6 (inside a conditional comment for instance) which doesn’t support :hover properly: jQuery(‘.parent’).hover(function () { jQuery(this).addClass(‘hover’); }, function () { jQuery(this).removeClass(‘hover’); }); Here’s a quick example: Fiddle

PHP – Find parent key of array

A little crude recursion, but it should work: function find_parent($array, $needle, $parent = null) { foreach ($array as $key => $value) { if (is_array($value)) { $pass = $parent; if (is_string($key)) { $pass = $key; } $found = find_parent($value, $needle, $pass); if ($found !== false) { return $found; } } else if ($key === ‘id’ && … Read more

Import from sibling directory

as a literal answer to the question ‘Python Import from parent directory‘: to import ‘mymodule’ that is in the parent directory of your current module: import os parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.sys.path.insert(0,parentdir) import mymodule edit Unfortunately, the __file__ attribute is not always set. A more secure way to get the parentdir is through the inspect module: … Read more