What would be an alternative to eval; evil?
Posted February 24th 2013, 11:51am
I'm wondering what an alternative could be for this: eval(onload_functions[i]); and eval('parent = document.' + id); I had to tear all my javascript files down for the time being
φ
Posts: 237
Joined: October 29th 2011, 11:00pm
Location: england, united kingdom, stoke on trent
Likes Given: 20
Likes Received: 4
What would be an alternative to eval; evil?
Posted February 24th 2013, 9:59pm
I know the first piece of crappy programming is in the overall_header.html template...where is the second?

There is no excuse for using eval() in javascript outside of very specific AJAX-related situations. It's lazy, crappy, and frankly dangerous programming. The alternative for the onload_functions garbage is to delete the garbage from overall_header.html, and executing the code properly in the template where it was set up. Here's an example...in login_body.html, you'll find the following code at the top:

<script type="text/javascript">
// <![CDATA[
onload_functions.push('document.getElementById("<!-- IF S_ADMIN_AUTH -->{PASSWORD_CREDENTIAL}<!-- ELSE -->{USERNAME_CREDENTIAL}<!-- ENDIF -->").focus();');
// ]]>
</script>

Delete it! Now, add the following code just above the <!-- INCLUDE overall_footer.html --> line:

<script type="text/javascript">
// <![CDATA[
document.getElementById("<!-- IF S_ADMIN_AUTH -->{PASSWORD_CREDENTIAL}<!-- ELSE -->{USERNAME_CREDENTIAL}<!-- ENDIF -->").focus();
// ]]>
</script>

Guess what? The javascript is properly executed without needing the onload_functions garbage! Repeat this in the other templates which contain these poorly-written pieces of junk, and you can delete the block in overall_header.html and be free of "pentapenguin" forever!

And...despite a rewite of the javascript, the "pentapenguin" garbage still infests phpBB3.1. :troll:
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
What would be an alternative to eval; evil?
Posted February 25th 2013, 5:51am
Even the var onload_functions = [];var onunload_functions = []; can be deleted too?
φ
Posts: 237
Joined: October 29th 2011, 11:00pm
Location: england, united kingdom, stoke on trent
Likes Given: 20
Likes Received: 4
What would be an alternative to eval; evil?
Posted February 25th 2013, 1:01pm
Yes, that can be deleted once you replace the onload_functions.push() garbage in every template as I described above. There are only a few templates which contain this crap, so it shouldn't take much time to do the replacements.
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357

Who is online

Users browsing this forum: No registered users and 1 guest