Access denied error with JS
Here comes an other iFrame question. I am trying to resize the iFrame acording to it's height. And found a nice JS function:
Code:
function calcHeight()
{
//find the height of the internal page
var the_height=
document.getElementById('the_iframe').contentWindow.
document.body.scrollHeight;
//change the height of the iframe
document.getElementById('the_iframe').height=
the_height;
}
But I am getting a JS error, access denied, on the first line. Anyone understand why? Is it because the content of the iFrame is on the other server or what?
ØØ
Re: Access denied error with JS
Again, are you running it from inside the IFRAME or outside the IFRAME?
Re: Access denied error with JS
[Little guy from Jerry McGuirre]You talk to much[/Little guy from Jerry McGuirre]
The function is in it's own js file. And I ran it like this (is this what is called in-line?):
Code:
<iframe width="700" id="the_iframe"
onLoad="calcHeight();"
src="testing_page.shtml"
scrolling="NO"
frameborder="1"
height="1">
</iframe>
So I guess that will say that it was the main page that called the function. And not called "from" the scr of the iFrame, if that was what you asked about.
Feel like a n00b for the first time in many years now...:D
ØØ
Re: Access denied error with JS
To add to that. This was the 2 simple steps that I tried to follow, and messed up anyway...:(
http://guymal.com/mycode/iframe_size/
Re: Access denied error with JS
Show me your page. I don't feel like creating an HTML file for this. :)
Re: Access denied error with JS
I have added the insanity back again. For your pleasure
:
Sample page comming up:
http://www.noteme.com/forum.php
js-file (only the first function, the two others was for an other test):
http://www.noteme.com/height.js
ØØ
Re: Access denied error with JS
Try this in the JS file:
Code:
document.getElementById('forum').document.body.scrollHeight
Re: Access denied error with JS
To not confuse you:
Code:
function calcHeight()
{
//find the height of the internal page
// var the_height = document.getElementById('forum').contentWindow.document.body.scrollHeight;
var the_height = document.getElementById('forum').document.body.scrollHeight;
//change the height of the iframe
document.getElementById('forum').height = the_height;
}
Re: Access denied error with JS
Sweet mother of J, that nearly worked..:)....at least the access problem is gone. But the size is still wrong.
I came over an other idea too. To send the info about the height from the web page in the iFrame (the forum), to the page that holds it. Will try that now, and get back to this thread if that fails..:)
ØØ
Re: Access denied error with JS
Quote:
Originally Posted by mendhak
To not confuse you:
Code:
function calcHeight()
{
//find the height of the internal page
// var the_height = document.getElementById('forum').contentWindow.document.body.scrollHeight;
var the_height = document.getElementById('forum').document.body.scrollHeight;
//change the height of the iframe
document.getElementById('forum').height = the_height;
}
I am not THAT easy to confuse...:) But thanks..:)...the error went away. Not sure why I can't use contentWindow, but it is probably a good reason..:)
Re: Access denied error with JS
I've never seen contentwindow being used with an IFRAME before. Then again, I haven't used many IFRAMES either. :D
Either way, with Iframes, I generally work directly with the document.
Re: Access denied error with JS
I have never used iFrames before either. Was told about their existence just a few hours ago, and they have given me head aches the same amount of hours....:(
ØØ