javascript

Reformatting for landscape view

I load a UIWebView from a string in a navigation based app. I'm using this in a UIWebView's header tag: <meta name="viewport" content="width=320,height=420,user-scalable=yes,initial-scale=1.0"> I use viewport at 1.0 because image sizes don't have to be readjusted, which is the case without viewport. When the phone is rotated to land...

How to create a method for an array class?

Sorry, I know this is programming 101, but I can't find any good documentation... I have an array, and I want to cast each member as an object and then call them by the name assigned (this would be so much simpler if javascript allowed for non-number index values). For instance: var things = ['chair', 'tv', 'bed']; var costs = ['10',...

jQuery and Rails

I'm writing a Rails app and need to plug in this little bit of jQuery code, but I don't really know how to get it to work. Here's my controller code: class ChatroomController < ApplicationController def send_data @role = Role.find_by_id(session[:role_id]) render :juggernaut do |page| page.insert_html :bottom, 'chat_data',...

Javascript: What is the difference between an array and an object?

The following two different code snippets seem equivalent to me: var myArray = Array(); myArray['A'] = "Athens"; myArray['B'] = "Berlin"; and var myObject = {'A': 'Athens', 'B':'Berlin'}; because they both behave the same, and also typeof(myArray) == typeof(myObjects) (both yield 'object'). Is there any difference between these va...

dynamicaly loaded js function does not appear in firebug js debugger

Hi. There is a page1.html (I open it in browser): <div id="content"> </div> <script type="text/JavaScript"> jQuery.ajax({ type : "GET", url : 'page2.html', dataType : "html", success : function(response) { jQuery('#content').append(response); } }); </script> Code of the page2.html: <script...

Loading extJS Combo Remotely not Working

This is my first bash at using extJS, and after a few hours of struggling, some things are working OK, except I have combo lists that I can't filter down to less than 2000 items in edge cases, so I'm trying to page the lists through remotely, but I must be doing something wrong. My data store and combo look as follows: var remoteStore ...

[Javascript] Background image at 100% of window (and resizes with it)

Duplicate of: Stretch and Scale CSS Background How do I stretch a background image to cover the entire HTML element? background image doesn’t stretch full page width I've got a webpage background image, which needs to be displayed fully at 100% of the window's size. If the window is resized, the image needs to resize with it, to stay a...

More compact way to do this?

I have a couple of functions that loop around the surrounding cells of a cell. The grid is contained inside an array. In my code, I have checks to make sure it's not one of the edge cells, as checking an undefined cell causes an error. As such, I have code like this: if(x > 0) { var firstX = x - 1; } else { var firstX = x; } i...

Only load HTML into an IFRAME

How can I only load the HTML of a page into an IFRAME, without automatically triggering the download of all the css,scripts,images,videos on the page? Or can you get an event the moment the DOM is "ready".. when the initial HTML has loaded and nothing much more. ...

Javascript "classes" (no frameworks)

I'm doing my first javascript project that makes heavy use of objects. Because of how it works, nearly all the custom objects are done like this: namespaceobj = {}; namespaceobj.subobject = {}; namespaceobj.subobject.somefunction = function(arg, uments) { // Do Stuff } namespaceobj.subobject.somedata = 10; namespaceobj.othersubject ...

Converting user input string to regular expression

I am designing a regular expression tester in html and javascript. The user will enter a regex, a string, and choose the function they want to test with (eg search, match, replace, etc. ) via radio button and the program will display the results when that function is run with the specified arguments. Naturally there will be extra text bo...

Load a page in the same window via javascript

How do you load a page in the same window via javascript? ...

jQuery Date Range Picker giving error in Google Chrome

I am using the jQuery Date Range Picker by the filament group. My code is such that I'm dynamically creating a textbox or rather an AJAX query returns HTML of a form. When I dump the HTML onto my page I call a script that invokes the daterangepicker() function supposed to turn an inputbox into a date range picker. My code works perfec...

Javascript: resize image to fit window, then toggle full size and adjust size on click?

Hi, I'm trying to create a small snippet to allow the onloaded image to be adjusted to fit the users resolution. And then allow the user to toggle between the actual image size, and the adjusted image size for their resolution. Here's what I got so far: <img src="<?=$file['direct_url']?>" border="0" onload="if(this.width>screen.width/1....

Remove JavaScript code from HTML

I'm looking for C# regular expression to replace/remove all JavaScript from HTML. Can someone please help me with the code? ...

How to measure characters in javascript and/or with jquery

I need to write in javascript (jquery) a function that is aware of the number of characters that fit in a line of the browser window. I'm using a monospace font to ease the problem, but it would be better if I generalize it for different fonts. How can I know how many characters would fill a row in the browser? The intention is to coun...

Resize jqGrid when browser is resized?

Is there any way to resize a jqGrid when the browser window is resized? I have tried the method described here but that technique does not work in IE7. ...

How best to redirect a webpage without using Javascript?

I have some script in my default page that redirects users to language specific versions of my website depending on the language of the browser. I want to add something that redirects those users who do NOT have Javascript enabled. Currently I have the following : <noscript> <META HTTP-EQUIV=REFRESH CONTENT="1; URL=en/index.htm">. </...

how to detect multi-byte characters inputting end by javascript?

currently I listen on "Enter" key to start sending a message, But for multi-byte characters,the "Enter" key is supposed to choose a certain character. The problem is that I've no idea how to detect whether a user is in the middle of inputting a multi-byte character,and even if he's in that process,the message will be sent the first ...

How to tell the difference between a page refresh and closing a page

I have a web app game and while in the game I want to have it so if a user closes the page or their browser, it will automatically log them out. I tried using the onbeforeunload event attached to the window: window.onbeforeunload = function() { // perform logout functions here } The problem is, that will also fire if the user refr...