client-side

Removing elements with Array.map in JavaScript

﹥>﹥吖頭↗ 提交于 2019-11-28 21:47:20
问题 I would like to filter an array of items by using the map() function. Here is a code snippet: var filteredItems = items.map(function(item) { if( ...some condition... ) { return item; } }); The problem is that filtered out items still uses space in the array and I would like to completely wipe them out. Any idea? EDIT: Thanks, I forgot about filter() , what I wanted is actually a filter() then a map() . EDIT2: Thanks for pointing that map() and filter() are not implemented in all browsers,

Can I modify or add cookies from JavaScript? [closed]

末鹿安然 提交于 2019-11-28 20:44:05
Exactly what are the restrictions for handling browser cookies from javascript? Can I check if cookies are enabled for example? Yes! Read this excellent article about using cookies with JavaScript Here's an excerpted code example. function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length

Save the document generated by javascript

故事扮演 提交于 2019-11-28 18:26:39
Javascript can manipulate the document the browser is displaying, so the following: <script> document.write("<table><tr><td>Hola</td><td>Adios</td></tr></table>"); </script> Will make the browser display a table just like if it was the original HTML document: <table> <tr> <td>Hola</td> <td>Adios</td> </tr> </table> Is there a way I can save/serve this document content? Currently we have some nicely generated reports using Ext-js, what I would like to do is to have the "text/html" version of it ( I mean, something that doesn't require javascript ) So at the end of the page I would add a button

How to keep API keys secret when using client side Javascript?

北慕城南 提交于 2019-11-28 17:45:15
For example, check out this Facebook plugin. In the client side the API key is clearly visible. What is stopping another user from obtaining this key and using this feature on a different site? I figured a very naive implementation would be to check the domain the request comes from but things like this are easy to fake. If I were to create something similar, how would I go about securing the authentication process? I want as much of this work to be client side, though some form of server authentication will be required surely? Any links or advice would be greatly appreciated. Update Similar

Which CSS selectors or rules can significantly affect front-end layout / rendering performance in the real world?

不羁的心 提交于 2019-11-28 15:23:08
Is it worth worrying about CSS rendering performance? Or should we just not worry about efficiency at all with CSS and just focus on writing elegant or maintainable CSS instead? This question is intended to be a useful resource for front-end developers on which parts of CSS can actually have a significant impact on device performance, and which devices / browsers or engines may be affected. This is not a question about how to write elegant or maintainable CSS, it's purely about performance (although hopefully what's written here can inform more general articles on best-practice). Existing

When to use “client-side routing” or “server-side routing”?

*爱你&永不变心* 提交于 2019-11-28 14:37:20
问题 I'm a little bit confused about this, and I feel slightly stupid asking this question, but I want to understand it. So, say I'm working with a client side web framework, like Backbone, Angular or Durandal. This framework includes routing. But I of course still have a server for database stuff, and so on, which also has routing. My question now is: When to use "client-side routing" or "server-side routing"? How is it "decided" whether routing is already performed on the client side or whether

Check filesize before upload

爱⌒轻易说出口 提交于 2019-11-28 14:13:16
I have a website that allows users to upload video files but I want to limit the filesize to 2MB , this is pretty straightforward after uploading the file but does anyone knows if I can check the file-size before uploading it so I don't overload the server unnecessarily ? I might be looking for a javascript/ajax solution but I don't have a clue on how to achieve this. Any help will be very welcome. Thanks guys! UPDATE: I need to check the file size on client-side and NOT on server-side , is this possible ? You can read local files in JavaScript using file reader in HTML5: http://www.html5rocks

ASP.NET confirm before executing codebehind

孤街醉人 提交于 2019-11-28 11:59:18
I have a form where a user can delete a record, and I want a pop up message where the user has to click okay to confirm the delete. Delete button: <asp:Button ID="btnDelete" runat="server" Text="Delete" UseSubmitBehavior="false" OnClick="btnDelete_Click" OnClientClick="confirmation();" /> Confirmation function: function confirmation() { var answer = confirm("Are you sure you want to delete? This action cannot be undone.") } So right now, clicking the delete button executes the btnDelete_Click Sub in the code behind regardless of whether you click okay or cancel in the pop up box. I know I can

custom validator MVC + validation client side

巧了我就是萌 提交于 2019-11-28 11:17:05
问题 I create a custom validateur in MVC 4: public class FirstNameValidator : ValidationAttribute { private IRegistrationConfiguration _registrationConfiguration; public string Category { get; set; } public bool IsLocal { get; set; } public FirstNameValidator() { _registrationConfiguration = DependencyResolver.Current.GetService<IRegistrationConfiguration>(); } public FirstNameValidator(IRegistrationConfiguration registrationConfiguration) { _registrationConfiguration = registrationConfiguration;

Determine IP# of domain from client browser

两盒软妹~` 提交于 2019-11-28 10:08:08
问题 Greetings all, I would very much like to determine the IP# of a domain from client script. It's for use in a testing application to determine whether or not a certain domain is set to a QA address as opposed to the address live on the . The testing machine will have it's host file set to resolve a domain to the QA address. Pinging from the server won't help since the server is getting the public DNS address. Is this possible in JavaScript? Maybe a Flash could do the trick? 回答1: Have a look at