Javascript Archives

Working with Date using Javascript

JavaScript has a built in function that allows you to work with dates. This feature is great for creating a calender, to display the current date, or to create a clock. You can also use the date function to set the date in your script.

Date Objects
Method Description
getDate() Returns the current date and time
getFullYear() Returns the four digit year
getYear() Returns the year in two digit format, ie 08
getUTCFullYear Returns the four digit year according to universal time.
getUTCYear Returns the year in two digit format according to universal time
getMonth Returns the month as a number, between 0 and 11
getUTCMonth Returns the month as a number according to universal time
getDate Returns the day of the month.
getUTCDate Returns the day of the month according to universal time
getDay() Returns the day of the week as a number between 0-6
getUTCDay() Returns the day of the week according to universal time

 

Time Objects
Method Description
getHour() Returns the hour in 24-hour format
getUTCHour() Returns the hour according to universal time in 24 hour format
getMinute() Returns the minute between 0 and 59
getUTCMinute() Returns the minute according to universal time
getSecond() Returns the second between 0 and 59
getUTCSecond() Returns the second according to universal time
getMillisecond() Returns the millisecond between 0 and 999
getUTCMillisecond() Returns the millisecond according to universal time
getTimezoneOffset() Returns the difference in minutes between GMT and local time

Get angle theta value in javascript

Returns the angle theta of x and y

Maximum of two numbers

Returns the value of the highest number
max(x,y)

natural logarithm in javascript

log(x)

Returns the natural logarithm of x

Java script to move an image

This code is used for moving  image in browser.

<html>
<h2>Move Image</h2>
<script type=”text/javascript”>
var X, Y;
window.document.onclick=moveImage;
function moveImage(){
X = (document.layers) ? e.pageX : event.clientX
Y = (document.layers) ? e.pageY : event.clientY
document.getElementById(‘image’).style.position=”absolute”;
document.getElementById(‘image’).style.left=X;
document.getElementById(‘image’).style.top=Y;
}
</script>
<img id=”image” src=”node.jpg”></img>
</html>

Detect iPhone orientation

Due to the fact that the iPhone allow its users to view a page in both portrait and landscape modes, you may need to be able to detect in which mode the document is being read.
This handy javascript function will detect the current iPhone orientation and will apply a specific CSS class so you can style it your way.

Detect iPhones and iPods using Javascript

When developing for the iPhone and the iPod Touch, the first thing we have to do is obviously detect it, so we can apply specific code or styles to it. The following code snippets will detect iPhones and iPods using Javascript, and redirect those users to an iPhone specific page.

List View using jQuerymobile

Using .js File as Resource in Xcode

By default, .js files are considered as files for compiling by xcode. So when we try to access the .js file in the resource, it will be returning a null value.

 

Here is the solution to avoid this issue. Go to the app target, then remove the .js file from the compile sources section and then add the files to the Copy Bundle Resources section. Now perform the Clean All Targets action and remove the app from the device or simulator if it is already installed.

 

Now you are ready to go. Just run the app and now you can see that you can access the .js file from the resource directly.

Incoming search terms:

  • where to put js file in cocoa

Getting the Index of ActiveItem in Sencha

The following line of code is used to get the index of activeitem in Sencha

Where,

newIndex -> a variable to store the index.

panel -> object of the panel

If there are 2 items in the panel and the value of newIndex is 0, then it represent the first items and if the value of newIndex is 1, then it represents the second item

Incoming search terms:

  • intitle:index of arduino youtube
Page 3 of 812345...Last »