Jump to content

JavaScript workaround


MrAdam

Recommended Posts

Just a quick question about working around non-js users... I couldn't find really anything useful through searching so thought perhaps somebody might have already dealt with this.Basically I'm creating a portfolio for myself. I want to have some really smoooth js features that gives the user that added wow effect, without making it unusable for users with js disabled. One of the features will be they click a thumbnail and up pops a nice big image of the site. I'm doing it with the onclick event. what I'd like to be able to do is say:

<a href="non-js-page.php?site=##"><img src="img/##_thumbnail.jpg" onclick="previewSite('##');" /></a>

where the onclick handles the js users, and the link handles non js users. I've tried a few things however the above runs the javascript then goes to the link. Does anybody know how I could get it to work?Cheers for any help! Adam

Link to comment
Share on other sites

Err? If JS is disabled, then the JS function won't run. That code should be fine (although why not put the onclick handler in the anchor?)

Link to comment
Share on other sites

Yeah but if the user has js enabled it runs the code, then after still goes to the page.. And its called with the onclick because I still want to be able to link non-js users to another page in the anchor..Cheers anyway though.. Adam

Link to comment
Share on other sites

Hm, that's not a good day ! It's been two times I post just after someone because of typing time !!! Anyway, that's orig message:No I think he means the OTHER way. Yes, when Js is disabled, the link will go, not the script. But if Js IS enabled, the script will go, then the link (and he doesn't want that).Maybe use <noscript> ?

Link to comment
Share on other sites

Ah yes. of course.. So would something like:

<a href="<noscript>non-js.php</noscript>"><img src="..." onclick="previewSite(##)" /></a>

Be the way to go? I've not used noscript before really, heard of it tho.. Am going to hav a quick read-up now..Cheers for the reply. Adam

Link to comment
Share on other sites

Oh I se what you mean, Adam.The easy solution is to set your JS function to return false, and then to do:

<a href="non-js-page.php?site=##" onclick="return previewSite('##');"><img src="img/##_thumbnail.jpg" /></a>

You could use noscript, but it is more logical to return false.

Link to comment
Share on other sites

You can do this:<a href="non-js-page.php?site=##" onclick="previewSite('##'); return false;"><img src="img/##_thumbnail.jpg" /></a>It will not open the link if javascript is enabled.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...