Results 1 to 12 of 12

Thread: Access denied error with JS

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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?



    ØØ

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Access denied error with JS

    Again, are you running it from inside the IFRAME or outside the IFRAME?

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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...



    ØØ

  4. #4

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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/

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Access denied error with JS

    Show me your page. I don't feel like creating an HTML file for this.

  6. #6

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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



    ØØ

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Access denied error with JS

    Try this in the JS file:

    Code:
    document.getElementById('forum').document.body.scrollHeight

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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;
    }

  9. #9

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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..



    ØØ

  10. #10

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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..

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

    Either way, with Iframes, I generally work directly with the document.

  12. #12

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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....



    ØØ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width