Categories
discuss

Is there a shorthand way to document.createElement multiple elements?

Is there a shorthand method in JS to document.createElement when you’re creating a bunch of elements.

To maximize usage of HTML5, and still make sites work in older browsers, I tend to have something like this snippet of JS in every site I do:

// Allows HTML5 tags to work in older browsers
document.createElement('header');
document.createElement('nav');
document.createElement('section');
document.createElement('article');
document.createElement('aside');
document.createElement('footer');

Is there a way to add them via one statement — comma separated or something similar?

Answer

var elements = ['header', 'nav', 'section', 'article', 'aside', 'footer'];
for (var i = 0; i < elements.length; i++) {
    document.createElement(elements[i]);
}
Categories
discuss

Javascript – Best way to encrypt data with password

I’m creating a server which can store cookies on the web that will contain application settings. The server will accept any data, but I want to encrypt all the settings before storing them in a cookie and decrypt them when reading them out. So I can store very sensitive data like Account Usernames & Passwords in the cookies and the server cannot do anything with it.

My question is now: What is the best way to encrypt such data with a password in JavaScript on the client side? What is the most secure?

I need some code that I can embed into my site and use it from there.

Answer

I’d recommend using AES encryption in your JavaScript code. See Javascript AES encryption for libraries and links. The trouble you’ll have is picking a key that is only available on the client side. Perhaps you can prompt the user? Or hash together some client system information that’s not sent to the server.

Categories
discuss

How do you access Android credential storage?

In Settings > Location & Security there is a section that allows the user to import certificates. There is also an option, “Use secure credentials” that “Allow[s] applications to access secure certificates and other credentials”. I can find no mention of how to get to this in the documentation, and very few mentions of it online aside from people using it to connect to certificate-secured wifi networks. One of the only pertinent things I found was a post claiming that accessing these certificates was actually impossible for regular apps. Is this true? Does anyone know how to access these certificates if it isn’t or documentation somewhere that states it is not possible?

Answer

Take a look at this Android Issue for some discussion on the topic:
http://code.google.com/p/android/issues/detail?id=11231

The Settings screen for installing root certificates can only be used for VPN and WiFi, unfortunately.

Categories
discuss

R cannot be resolved – Android, no import android.R; statement

Ok,
I am working on a new app and everything worked fine as long as I used a Relative View. However, I want a tabbed layout so I switched what I had (not much so far since I just got it reading from a DB and settings working) over to a tabbed view. Since that time, any class that has any R. statement in it has an “R cannot be resolved” error. I am following the tutorial from the Android “Hello Views” tutorial so I am assuming that isn’t the issue (but it could still be).

Answer

I have a few suggestions:

  1. Make sure you don’t have any other errors other than the R-related errors. Right-click your project folder in Eclipse, Android Tools -> Fix Project Properties.

  2. Check to make sure you have the correct R imported. Sometimes the default Android.R can be imported.

  3. Check for errors in your layout XML files.

Categories
discuss

Maven – Always download sources and javadocs

Is there a way I can configure maven to always download sources and javadocs? Specifying -DdownloadSources=true -DdownloadJavadocs=true everytime (which usually goes along with running mvn compile twice because I forgot the first time) becomes rather tedious.

Answer

Open your settings.xml file ~/.m2/settings.xml (create it if it doesn’t exist). Add a section with the properties added. Then make sure the activeProfiles includes the new profile.

<settings>

   <!-- ... other settings here ... -->

    <profiles>
        <profile>
            <id>downloadSources</id>
            <properties>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </properties>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>downloadSources</activeProfile>
    </activeProfiles>
</settings>
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..