/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mrhooSep 09.2010 — 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.
Copy linkTweet thisAlerts:
@captsigauthorSep 10.2010 — thanks for taking the time to respond to me. I started using alerts instead of document.write and the error message went away.

captsig
×

Success!

Help @captsig spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...