Discuss Trouble getting events to fire in an iframe in the JavaScript Development forum on Dev Shed. Trouble getting events to fire in an iframe JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.
Posts: 13
Time spent in forums: 1 h 48 m 30 sec
Reputation Power: 0
Trouble getting events to fire in an iframe
I have a CMS system that uses an HTML widgeditor.
When a div with a correct class is clicked a floating div pops up where the user can edit the html etc.
This div uses an iframe and there is an issue with IE that won't allow relative links to be added to iframe.
http://www.thescripts.com/forum/thread89029.html
http://freetextbox.com/forums/thread/4977.aspx
I need the ability to add relative links, the cms sys is also used by our admin guys to set up html/text etc for other sites from this site. Anyway I used the example in that link and came up with a function to replace the old .innerHTML call but now the events that were firing (keydown,mouseup,keyup) are not firing in IE.
So I have tried writing the event handlers inline to this function so that they are included into the iframe however they are still not firing. If I take the html for the iframe out and put it in a page by itself it works fine so why isn't it working when its in the iframe.
If I take the rendered html out and put it in a file by itself like the following it works fine:
<html>
<head>
<link href="/jobboard/widgeditor/css/widgContent.css" rel="stylesheet" type="text/css" />
</head>
<body id="iframeBody">
<P>Praesent sed nibh eget justo tristique commodo. Phasellus justo dolor, vulputate nec, mollis ac, tempus et, orci. Praesent et justo eget quam aliquam tristique. Nam vitae mi sit amet odio viverra aliquet. Nunc eleifend felis in leo. Vivamus rhoncus turpis ut lorem. Phasellus sollicitudin, pede quis lobortis laoreet, pede nibh elementum nunc, vel pellentesque turpis dui et felis. Cras lorem nulla, vulputate condimentum, pellentesque id, mattis eget, ipsum. Proin sit amet elit. Aliquam aliquet pede at ipsum. Sed malesuada condimentum nulla. Praesent urna est, feugiat ac, pellentesque nec, condimentum non, lacus. Praesent congue vestibulum libero. Quisque non pede. Sed eu tellus nec nulla ultricies ornare.</P>
</body>
<script type="text/javascript">
<!--
var myElem = document.getElementById('iframeBody');
if (myElem.attachEvent)
{
myElem.attachEvent("onmouseup", function(){testEvent(); return true;});
myElem.attachEvent("onkeyup", function(){testEvent(); return true;});
myElem.attachEvent("onkeydown", function(e){testEvent(); return true;}, false);
}
else
{
myElem.addEventListener("mouseup", function(){testEvent(); return true;}, false);
myElem.addEventListener("keyup", function(){testEvent(); return true;}, false);
myElem.addEventListener("keydown", function(e){testEvent(); return true;}, false);
}
function testEvent(){
alert('event firing!')
};
//-->
</script>
</html>
I am hoping those event handlers will call functions that are declared in the document that includes the iframe but at the moment I can't even get this test function to fire.