dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: javascript method causes 'permission denied'

  1. #1
    Join Date
    Oct 2008
    Location
    moreno valley, California ,usa
    Posts
    161

    javascript method causes 'permission denied'

    Valued colleagues,
    this is baffling; I'm following an example out of Patrick Carey's latest book, and I get a "permission denied" error when the code hits a particular line. In his example, you're trying to create a collection(array) of elements with a class name of "menu" by sifting through all of the elements using the wildcard
    "*"; see the code below. When the program hits - if(allEle[i].className=="menu") -- it causes the error. The write statements just above this prove that it gets to that line and chokes; the allEle collection (array) is 41 items long; here is the relevant stretch of code:

    <script type="text/javascript" >
    var activemenu=null;
    window.onload=init;
    function init()
    {
    var menus=new Array();
    var allEle=document.getElementsByTagName("*");
    for(var i=0;i<allEle.length; i++)
    {
    document.write("allele length value is:" + allEle.length + " <br />");
    document.write("here is one loop" + "<br />");
    if(allEle[i].className=="menu")
    {
    menus.push(allEle[i]);
    }
    }//end for loop


    I would greatly appreciate any suggestions.

    captsig

  2. #2
    Join Date
    Feb 2006
    Posts
    2,927
    Two things are going on-
    you are opening a new document with document.write,
    and you are increasing the length of the node list with each pass through the loop, so it can never end.

  3. #3
    Join Date
    Oct 2008
    Location
    moreno valley, California ,usa
    Posts
    161
    thanks for taking the time to respond to me. I started using alerts instead of document.write and the error message went away.

    captsig

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles