javascript

Using an anchor as a javascript action, what should the link be?

I've seen (and used) code to have a link spawn a javascript action many times in my life, but I've never come to a firm conclusion on if the href attribute should be blank or #. Do you have any preference one way or the other, and if so, why? <a href="" onclick="javascript: DoSomething();">linky</a> or <a href="#" onclick="javascrip...

different WAR files, shared resources

Suppose you have several applications which share the same code and most of the other resources, but have a somewhat different look and feel, some labels change, etc. (think branding). If each web app is to go in its own WAR file, where do you put the shared resources? I already use the classpath to share classes and property files. Bu...

Converting COM object returned by IHTMLDocument2.Script.InvokeMember() to something useful

I'm working with some code in C#.NET for an Internet Explorer extension that calls Javascript in the browser and gets the return value from the Javascript call. When the Javascript returns a primitive type or an array of primitive types, I get something that I can deal with, but when the Javascript returns an object, I get an opaque COM...

JQuery focus

Let say i have the next markup: <div id="content"> <div id="firstP"><p>First paragraph</p></div> <div id="secondP"><p>Second paragraph</p></div> <div id="thirdP"><p>Third paragraph</p></div> <div id="fourthP"><p>Fourth paragraph</p></div> </div> I want to add a new div with Javascript and focus in this new element. Fo...

Which JavaScript library you recommend to use with J2EE + Struts + iBatis ?

Which JavaScript library you recommend to use with J2EE + Struts + iBatis ? Something like Ext JS, Dojo, frameworks that can be easily integrated with Struts. ...

Javascript URL replacement on google sponsored links

How does URL replacement on the google SERPs "sponsored links" work? Some of the results have a function rwt attached to the onmousedown event, but the sponsored links don't have any event handlers as far as I can make out. How does it achieve the behaviour of replacing the href, and still send you to the long /aclk?sa= link? Upon savi...

IE6 can't find Object element with getElementById()?

I'm trying to get an object element from my webpage using getElementById (ultimately so I can replace it with a dynamically created object element) but it is returning null in IE6. In the following code, the byId() function returns null in IE but an [object HTMLObjectElement] in Firefox 3 and the lengthOfByTagName() function returns 0 i...

Detecting Vista IE7 Protected Mode with Javascript

I'd like to be able to detect Vista IE7 Protected Mode within a page using javascript, preferably. My thinking is to perform an action that would violate protected mode, thus exposing it. The goal is to give appropriate site help messaging to IE7 Vista users. ...

Editing Javascript for Vista Buttons

I generated drop down menus for my site in Vista Buttons. When it exports the buttons, they are in a .js file along with graphics files and .css to control everything. I did some extensive editing on the .css, and then decided to change all the .html extensions for the links that the menus are pointing to, to .php, because I am now usin...

How to Toggle confirm message box from aspx.cs page

I have a search program that will be looking at a database from a database. If the date range is more than 3 weeks I want to alert them that it might take a while with all the data in the database. I have a confirm message box in a javascript funtion. I want to check the date range in the aspx.cs page. how do I totrigger the message ...

How do I get the URL path after a redirect -- with Javascript?

This could be a little off the ballpark, but a friend asked me about it and it's kind of bothering me. How do you figure out the current path in your address bar if the server redirects all requests to a default file, say, index.html. Let's say you entered: www.example.com/ And your server configuration automatically redirects this r...

jQuery .getJSON Firefox 3 Syntax Error Undefined

I'm getting a syntax error (undefined line 1 test.js) in Firefox 3 when I run this code. The alert works properly (it displays 'work') but I have no idea why I am receiving the syntax error. jQuery code: $.getJSON("json/test.js", function(data) { alert(data[0].test); }); test.js: [{"test": "work"}] Any ideas? I'm working on ...

Simple JavaScript problem: onClick confirm not preventing default action

I'm making a simple remove link with an onClick event that brings up a confirm dialog. I want to confirm that the user wants to delete an entry. However, it seems that when Cancel is clicked in the dialog, the default action (i.e. the href link) is still taking place, so the entry still gets deleted. Not sure what I'm doing wrong here......

if statement inside a variable

I am building a conditional navigation menu that has 3 levels (the 3rd level added today by business, no worries its not like I launch next week. Oh wait I do:)). I have a javascript var that contains the html for my first conditional level. I am now trying to insert another level inside of the first. var myVar = '<ul class="linksUnit"...

how can I check what site a javascript badge is embedded on?

I want to allow users to embed badges on their personal site or blogs with a snippet of javascript. The badge is customized on our site based on information in their profiles that at some point is "approved". Is there a best practice to check what website the javascript is embedded on and if it does not match the website in their "appr...

How to tell if a DOM element is displayed?

This is not to be confused with "How to tell if a DOM element is visible?" I want to determine if a given DOM element is visible on the page. E.g. if the element is a child of a parent which has display:none; set, then it won't be visible. (This has nothing to do with whether the element is in the viewport or not) I could iterate thro...

Javascript + IMG tags = memory leak. Is there a better way to do this?

I've got a web page that's using jquery to receive some product information as people are looking at things and then displays the last product images that were seen. This is in a jquery AJAX callback that looks pretty much like this: if(number_of_things_seen > 10) { $('#shots li:last-child').remove(); } $('<li><img src="' + p.Produc...

FileUpload Using Ajax In ASP.NET With C#

Hi Guys, I need to upload images using FileUpload without postback(using Ajax).I tried many examples.But in all postback is coming or they are using PHP.Can anyone help me to do single file upload or multi file upload using ajax in ASP.Net with C#. ...

Explicit script end tag always converted to self-closing

I'm using xslt to transform xml to an aspx file. In the xslt, I have a script tag to include a jquery.js file. To get it to work with IE, the script tag must have an explicit closing tag. For some reason, this doesn't work with xslt below. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/...

Are there any pre-built Javascripts for checking keyboard/mouse activity?

I need a Javascript which monitors keyboard and mouse events to track how much time a user spends on the page. Specifically, actively using the page by typing, or moving/clicking with the mouse. Thought I'd ask if anybody knows of something that might work for me to save some time. Otherwise, Javascript and Aspirin here I come... lol ...