Sign in to follow this  
walkingcarcass

[web] *!%$#ing JavaScript!

Recommended Posts

Sorry to shove this in the lounge, but it's kinda urgent. I have an iframe and was editing its contents via document.getElementById(iframe_id).contentDocument.body.innerHTML This, or something very similar, was working earlier today. I deleted and re-typed the line and now instead of editing the frame, it throws an exception:
Quote:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLElement.innerHTML]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: file:///home/s0347735/Work/RF3k_map/maps/mapScript.js :: scrollTo :: line 279" data: no]
Interestingly, I can READ the innerHTML with no worries. Also, suddenly, frameobject.contentDocument.evaluate(anything) throws a "not enough arguments" exception. I've re-started firefox and examined the DOM and am now shedding tears of blood cos I overwrote the last working version (it was such a small change...). Please help. Make me look stupid if you have to.

Share this post


Link to post
Share on other sites
Source code? Well here's a stripped-down version.
Quote:
<html><head><title>Test IFRAME</title></head>
<body>
<script type="text/javascript">
function doIt(){
alert(document.getElementById("my_if").contentDocument.body.innerHTML);
document.getElementById("my_if").contentDocument.body.innerHTML=
document.getElementById("my_in").value;
}
</script>
<iframe id="my_if" width="300" height="300"
src="view.xhtml"></iframe>
<br /><input id="my_in" type="text" value="Test Me" /><button type="button"
onclick="javascript:doIt()">Click</button>


and view.xhtml is
Quote:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="style.css" />
<title>IFRAME content</title>
</head>

<body style="background: white">
<p>Initial content</p>
</body>
</html>

Share this post


Link to post
Share on other sites
Now this is getting really odd. I changed the xhtml to an equiavlent html and include a function in bigview like this

function test(t){
alert(t);
}

And in the parent window have
frames["name"].eval("test('Testing...')");

Which worked. I changed alert(t) to document.body.innerHTML=t which again caused an exception

Then I put a width,height:100% div at position 0,0 and tried divobject.innerHTML=t which also crashed, which is odd since the same approach works in other web pages

Here's the really wierd part...

To test I wasn't going mad I added this to just before the </body>
<script type="text/javascript">test("abc")</script>


Not only does that work, but the existing code in the parent window successfuly sets the contents of the div as well!

Somehow it seems a page's contents can only be externally set if the page itself has performed a similar operation. If it's not a bug it's a pretty obscure feature.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this