javascript

How can I make external code 'safe' to run? Just ban eval()?

I'd like to be able to allow community members to supply their own javascript code for others to use, because the users' imaginations are collectively far greater than anything I could think of. But this raises the inherent question of security, particularly when the purpose is to allow external code to run. So, can I just ban eval() f...

Returning HTML from JSON webservice - what is the ".d" ?

Hi This is one of those situations where I've had to pick up and run with a new tech without having time to learn the foundations! I have the following js function which calls out to PrintService, which returns me the HTML to inject into a div: function showPrintDialog() { $.ajax({ type: "POST", ...

FInd Javascript Error In IE 7?

I had Put a digg button in my blog. The blog runs fine on firefox and opera,but when i open it in ie7 it shows javascript error.clicking on that little triangle doesn't show any information..how to remove that error? ...

How to pass an array in Django to a template and use it with JavaScript

I want to pass an Array to a template and afterwards use it via JavaScript. In my views.py I have: arry1= ['Str',500,20] return render_to_response('test.html', {'array1': arry1}) var array1 = {{ array1 }}; but when I visit the website it puts out: var array1 = [_39;Str_39;,500,20]; (without the _ sign (otherwise stackoverflow change...

User control - calling a vb linkbutton's(within a user control) click event from javascript

how can i call a VB function - deleteevent() in usercontrol.ascx.vb from a javascript function in clickhandler(e) in usercontrol.ascx. The call should cause a postback because i need the usercontrol to display the changes. i am currently trying to do it by using a linkbutton with style display:none, and calling its click event from the ...

Which mechanism may be used to access Java methods which conflict with JavaScript keywords?

I've a Javascript source that uses a Java class that defines a "delete" method (using jdk6 scripting). Since delete is a keyword, I cannot invoke that method. In JavaFX script any sequence of characters enclosed in <> is treated as a lexical identifier. So you can use "insert", that is a keyword, as an identifier: var textField = new ...

How to use jQuery to get the current value of a file input field

From what I've ready you should be able to use the 'value' property of a file input field to get the currently set path of that field. But when I do this: $('#fileinput').value() I get 'undefined'. The ID of the field is set to "fileinput" I'm sure. Does anyone have any thoughts on why this might not be working for me? And by the...

How to use innerHTML on plain txt files in Firefox?

If you open a text file (.txt, .js, .css, ...) in your browser, it will get wrapped up in a nice DOM tree. For example, open this .txt file and enter javascript:alert(document.documentElement.innerHTML); into your address bar. Nice... every major browser supports DOM manipulation on this wrapped text files, which is a great thing for...

Adding options to a select using Jquery/javascript

What's the easiest way to add an option to a dropdown using javascript? Can this work? $("#mySelect").append('<option value=1>My option</option>'); ...

Only supporting users who have Javascript enabled.

I am considering creating a website that only supports users with JavaScript enabled. My justification for this is that I want to offer a rich user experience, in a fairly limited time budget, so if I only support people who have JS enabled, I don't have to spend time making sure the UI works without JS and create server side equivalent...

Strange off-by-one issue with snippet to generate gradients...

I use my own library for a lot of stuff, and recently I decided to add gradient functionality, but I've encountered a problem that I seem to remember having a while ago also, and this is the matter of my gradient being slightly off near the end. First, the code in question: gradient = function(l, g) { var r = [], s = [], f = g.length -...

getting a Webkit executeSql transaction to return a value

How can I get the following JavaScript to return row so I can access it outside the transaction? All of Apple's example code seems to have HTML written to the browser within the transaction instead of ever passing data back to a calling function. Along the lines of: function getData() { db.transaction(function(tx) { tx.executeSql...

Checking for a valid url using Javascript Regular Expressions

What is the expression I should use in order to check for a valid url in javascript? ...

popup goes back to hidden state when clicking outside the popup area

If I have a popup (using a div), how can I have the div to go back to the hidden state when someone clicks anywhere outside of the div? i.e. the popup is visible, then someone clicks outside the popup, the div should be hidden again. How can I achieve this functionality? ...

Unable to get Id of draggable divs in jquery. (using jqery ui)

For some reason the script below is unable to get the id of the draggable divs using attr('id'), but it works on the other static elements on the page. I am totally confused as to why this wont work and if anyone has a solution for me it would me much appreciated. $(document).ready(function(){ //$(".draggable").d...

How to replace the currently selected text inside an html textarea?

How do I edit the selected text of a textarea form element? EDIT: as in edit it in-place, replacing the orignal text. ...

How can I remove the event handler once the click event has fired?

I have a click event I wired up on a div on my page. Once the click event has fired, I want to unbind the event on that div. How can I do this? Can I unbind it in the click event handler itself? ...

How do I remove characters from a textbox when the number of characters exceeds a certain limit?

I would like to implement a text box with a 140 character limit in Javascript such that when the 141st character is added that character is erased. I don't want to show any message or alert to user they have exceeded the limit. There is already a counter.re. Here is an example of what I want to do: http://titletweets.com/category/games...

Javascript - load events for embed elements

If I do an online onload event for embed objects, that seems to work but I can't seem to get the load event working through addEventListener. Is this expected? ...

Should I use double-quotes or single-quotes for quoting strings if I want to be consistent across multiple languages?

In JavaScript, it doesn't seem to matter whether you use single quotes or double quotes when writing strings. However, some programming languages treat them differently. Is one more reliable than the other across multiple programming languages? Are there any pros or cons using one rather than the other (apart from when apostrophes or qu...