SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed with JavaScript warning

    Hi people

    I get the following strange (for me at least) JavaScript warning
    When I display page iframe.php inside an <iframe> tag in my main page:
    Code:
    Error: [Exception... "'Permission denied to get property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]"  nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)"  location: "JS frame :: http://localhost/iframe.php :: bodyLoaded :: line 49"  data: no]
    Source File: http://localhost/iframe.php
    Line: 49
    The error is in the following JavaScript function:
    Code:
    function bodyLoaded() {			
    	
    	this.focus();   // This is causing a JavaScript warnings
    }
    What I am trying to do is to cause the iframe content to grab the focus of the browser as soon as it gets loaded
    The bodyLoaded() function is invoked in the onload() event for the iframe page (iframe.php)

    The reason I am doing this is that I need the iframe to respond to keydown events, and it will only do so
    if it has the focus.
    I don't want to wait for the user to click the iframe in order for it to get the focus.
    I need it to obtain the focus automatically as soon as it gets loaded (system requirement)

    My solution works, but I keep getting this JavaScript warning, which worries me.

    Can anyone see what could be causing it?
    If this is not the correct way to achieve what I want, I would appreciate any suggestion on the correct
    way to go about doing this

    regards
    Jason

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of testing it locally, try testing it with a remote server.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have any problem capturing the keydown with this code using localhost and IE6 and FF1:

    MainPage.htm:
    Code:
    <html>
    <head><title></title>
    </head>
    
    <body onkeydown="alert('mainpage: keydown')">
    <div>Main Page</div>
    <div>------------</div>
    
    <div>
    	<iframe name="Big" ID="Big" width="100%" height="50%"
    	     border="0" frameborder="0" src="iframe_page1.htm" marginwidth="1" marginheight="1">
    	</iframe
    </div>
    
    <div>------------</div>
    <div>Main Page</div>
    
    
    </body>
    </html>
    iframe_page1.htm:
    Code:
    <html>
    <title></title>
    <head>
    <script type="text/javascript">
    <!-- Hide from browsers lacking javascript
    
    window.onload=function()
    {
    	this.focus(); //comment this line out to see the difference
    };
    
    
    // End hiding -->
    </script>
    </head>
    
    <body onkeydown="alert('iframe: keydown')">
    
    <div id="d">iframe</div>
     
    <form name="f" method="post" action="">
    <div><input type="text" id="tb0"/></div>
    <div><input type="text" id="" /></div>
    <div><input type="text" id="" /></div>
    <div><input type="text" id="" /></div>
    <div><input type="text" id="" /></div>
    <div><input type="text" id="" /></div>
    <div><input type="text" id="" /></div>
    <div><input type="text" id="" /></div>
    </form>
    
    </body>
    </html>
    Last edited by 7stud; Oct 21, 2005 at 20:11.

  4. #4
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was told that this is an old Firefox bug and that I should ignore it
    I find it hard to believe that I should dismiss it so easily

    I just found that this bug is only happening when running my code locally
    using localhost

    this is interesting


Bookmarks

Posting Permissions

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