javascript

javascript: find strings in dom and emphasize it

i want a function that finds some strings i've got in an array in the DOM and emphasize it. eg. keywords[0] = 'linux'; keywords[1] = 'suse pro'; <body> im a huge fan of <em>linux</em> and at the moment im using <em>suse pro</em> and finds it amazing. </body> how do i do it in the easiest way. thanks in advance EDIT: i found ...

Math.random() - Not random

I created a jQuery plugin but I have a problem, I use the following code: Math.floor(Math.random()*500) I add the result to a element, but bizarrely the result is every time the same. If I add a alert() to the line after the random-number-generation, I get random values, why? I want to get without the alert() random integers. But how...

Dynamically added HTML not being recognized by Jquery

Read some other things on here re: this similar problem but am not sure how to apply this to my dilemma. I have a jquery function that replaces some HTML in a list.. For example, before the function runs: <ul id="mylist"> <li id="item1">blah blah blah</li> <li id="item2">blah blah blah</li> <li id="item3">blah blah blah</li> </ul> Th...

rawurldecode and regexp for splitting words with and without quotes in javascript?

so here is the case: i have a string in php (containts 2 words): windows "mac os" i encode it with rawurlencode and put it in the URL after ?name= in an anchor. when i click it i see the following in the browsers url. index.php?name=windows%20%5C%22mac%20os%5C%22 and then i get it with javascript with jquery bbq. var string = $.de...

Getting HTML out of selection / range from a web page in Mozilla Firefox

Hello, I currently using the following the get the selected text from a webpage into a custom firefox extension: getSelectedText: function(){ var textWindow = document.commandDispatcher.focusedWindow; var text = textWindow.getSelection(); if (text == null) {text =' ';} text = text.toString(); text = text.repla...

Caps Lock script cleanup

I was wondering if someone could help me clean up this code if possible; including merging the two functions into one. I'm new to javascript so I could really use some help. I was able to get this script working quite well, I just want to know if it can be refined and/or if there are any problems with it that I overlooked. The script ...

XML Parsing in Javascript

I'm trying to parse an xml coming from an XMLHttpRequest (for a Firefox extension). In the following code, req is an XMLHttpRequest object. I did req.overrideMimeType("text/xml"); after declaring req. var shortURL; var xmlDoc = document.implementation.createDocument("","",null); xmlDoc.async = false; xmlDoc = req.responseXml; i...

Resize jqGrid based on number of rows?

I want my jqGrid to shrink and expand based on the number of rows it has. Let say it currently has 10 rows, the height of the jqGrid will shrink to 10 rows (so that no gaping empty rows is exposed). If however there are too many rows, the height of the grid will expand to a maximum 'height' value and a scroll bar will appear. ...

IE leaks memory for dynamically generated javascript

Recently I have to execute script retrieved thru Ajax from web server periodically. I do it by first creating a Script tag and assign the text attribute to run the script. Then, I dispose the script tag just to find out that memory keep increasing on every creation in IE 7. The following HTML illustrate the problem: <html> <body> <span ...

Simple AJAX code not being recognized

Hi, I'm trying to begin learning AJAX, and I've already hit a little stump. So I'm starting simple and just trying to get an alert to pop up showing the length of the string the user types into a text field. The HTML: <form action="/scripts/addemail_fb.php" method="post"> <input type="text" name="email" value="Enter your email here!" /...

Parsing JSON from XmlHttpRequest.responseJSON

I'm trying to parse bit.ly JSON reply in javscript. I get the JSON vis XmlHttpRequest. var req = new XMLHttpRequest; req.overrideMimeType("application/json"); req.open('GET', BITLY_CREATE_API + encodeURIComponent(url) + BITLY_API_LOGIN, true); var target = this; req.onload = function() {target.parseJSON(req, url)}; req.send(null); pa...

regular expressions - same for all languages?

is the regexp the same between languages? for example. if i want to use it in javascript, would i have to search for regexp for javascript specifically. cause i got some cheat sheets. it just says regular expression. i wonder if i could use this on all languages, php, javascript and so on. ...

How can I count a page views?

How can I count page views so that when I go and refresh the page the counter doesn't consider it as new view? ...

Dynamically Including jQuery using JavaScript if it's not already present

I'm writing a little JavaScript tool for myself that I plan on making available to other people and it uses jQuery. My dream for this little utility is for people to be able to include a single .js file from a remote source and, when that file is loaded, have it check to see if jQuery has already been included and, if it has, make sure i...

How to get a web page input datas?

Am very New to Web Page Development. In my website i have the help page like Name, Email ID, Contact No, Comment and Submit Button Suppose i entered the data in the help page , then i press submit button means that entered data's should sent to the email account For Example Help Page Name - Raja Email - [email protected] Contact - 98763...

URL Hash modification after document.write()

Hi!, I download via jQuery AJAX a whole html webpage. I want to replace the content of the current page with the one downloaded via ajax. I do it with document.write(). It doesn't work correctly because whenever I try to modify the hash, the webpage is reloaded. I know in IE it it necessary an iframe, but that is not the problem, becau...

document.forms['form_preview'] Undefined Error: Javascript

Hi, I'm facing problem as of bellow, <form name="form_preview" id="form_preview" action="xxxx.php" method="POST" target="iframe_p"> <input type="hidden" name="post_data" id="post_data" value="xxxxxxxx"> </form> <script language="JavaScript"> document.forms['form_preview'].submit(); </script> I'm having nes...

autoversioning image links INSIDE css and javascript files?

Hi folks! Inside my PHP application, I'm already successfully autoversioning my static content (CSS, JS, and images), so my URLs look something like this: <link rel="stylesheet" href="http://example.com/include/css/global.1262063295.css" type="text/css" media="all" /> <img src="http://example.com/images/logo.1254284339.png" alt="" /> ...

Override TAB inside a Browser

If I'm typing text in a input field and press ENTER the default behavior of all the browsers I know is to submit the form, however if I press ENTER inside a textarea a new line is added. Is there any way to mimic this behavior (indent, not submit the form) whenever I press TAB inside a textarea? Bespin seems to do it, but in a canvas el...

Mocking a javascript method with ScrewUnit

Hi. I have a simple validation method as follows function someMethod { //some processing } I want to unit test this method. What is the simplest way I can mock it. Usually if I have an object as follows: var someObject = function() { reload : function() { //reload logic here } } I can stub someObject and then check if...