/    Sign up×
Community /Pin to ProfileBookmark

IFrame Drops Contents on Drag

I am in quite the strange predicament. I’m developing one of those newfangled HTML Editors (using .contentsEditable on a DIV tag) and have a fairly major problem when trying to work with an IFRAME element inside that editor. I write the IFRAME dynamically and stick some contents into it using the .write() method, and all of that goes well. The problem is that when I drag and drop the IFRAME to another place within the editor, it’s contents disappear! Sounds like a little Microsoft Magic to me.

My code is pasted below. If you want to see this thing in action (without downloading and running the code), I also uploaded it to [URL=http://www.grinn.net/temp/stupidCode.htm]http://www.grinn.net/temp/stupidCode.htm[/URL].

[CODE]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

<html>
<head>
<title>Divs over cells.</title>
<script>
<!—
function offW(el) {
// Return the width of an element.
var w;
w = el.offsetWidth;
return w;
}

function offH(el) {
// Return the height of an element.
var h;
h = el.offsetHeight;
return h;
}
function makeEditable() {
document.getElementById(“layoutBox”).contentEditable = true;
}

function encloseItems() {
var e = document.createElement(‘<iframe name=”testFrame”></iframe>’);
var editor = document.getElementById(“layoutBox”).document;
var curSpan = editor.getElementById(“testCell”);
e.id = “testFrame”;
e.width = (offW(curSpan)*1.0185)+19;
e.height = offH(curSpan)+4;
e.marginHeight = 0;
e.marginWidth = 0;
var preserve = curSpan.innerHTML;
curSpan.replaceNode(e);
e = document.frames[“testFrame”]
var frameDoc = e.document;
frameDoc.open();
frameDoc.write(preserve);
frameDoc.close();
}

function getHTML() {
return document.frames[“testFrame”].document.body.innerHTML;
}
//—>
</script>
</head>
<body onLoad=”makeEditable()”>
This is the editor:
<div id=”layoutBox” style=”border: 2px ridge Black; height:250px;”>
<span id=”testCell”><b>This is the iFrame “testFrame”</b><br>If you drag and drop it, it will loose it’s contents.</span><br>
This is some text.
</div>
<form name=”form1″>
<input type=”button” onClick=”alert(getHTML());” value=”Show testFrame innerHTML”>
</form>
<script>encloseItems();</script>
</body>
</html>
[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @grinndaddy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...