PDA

View Full Version : Can I use onClick to just go to a URL



somnamblst
July 23rd, 2008, 11:47 AM
OK I admit I am violating CSS by wrapping an HREF around a div but I have done this before with full knowledge that it is not done but it worked in other instances including empty divs & nested divs with other javascript widgets like Hide All except One with no problem.

The one that this is not working is a javascript scroller based on this example.
http://jscroller2.markusbordihn.de/example/

My HREF does click thru in FF but not in IE.

Could I try something like
<a href="http://yahoo.com" OnClick="MyFunction(getURL);" title="Click here">

actionAction
July 23rd, 2008, 12:40 PM
It's not CSS standards, it's W3C and DOM standards that are being violated by this. Yes, you can use onclick to just go to a url using window.location.href = 'yourfile.html', but it should be in your div element, not in an anchor tag wrapping the div. You can put a regular anchor tag inside of the div (also inside of a noscript) tag to ensure that users without Javascript will be able to use your site.

somnamblst
July 23rd, 2008, 01:30 PM
It's not CSS standards, it's W3C and DOM standards that are being violated by this. Yes, you can use onclick to just go to a url using window.location.href = 'yourfile.html', but it should be in your div element, not in an anchor tag wrapping the div. You can put a regular anchor tag inside of the div (also inside of a noscript) tag to ensure that users without Javascript will be able to use your site.

Thanks!

this works


<div id="wrapp" onClick="window.open('http://yahoo.com','_blank');">

One more question, is there a way to tell this method of linking to another page to show a hand cursor for useability?

actionAction
July 23rd, 2008, 02:34 PM
No problem! In the css, put:

#wrapp{/* not sure if there are supposed to be two ps there in wrap */
cursor:hand;
}

somnamblst
July 23rd, 2008, 03:20 PM
No problem! In the css, put:

#wrapp{/* not sure if there are supposed to be two ps there in wrap */
cursor:hand;
}

I do have that in my style, only appears to work for IE but the addition of onClick="window.open seems to have overridden that style.

I misspell words like wrapp on purpose so I lessen the likelihood of other style sheet conflicts.

actionAction
July 23rd, 2008, 03:32 PM
sorry, it should be pointer, not hand.