/    Sign up×
Community /Pin to ProfileBookmark

a href onClick

how do I redirect user to another site when he clicks on an image using onClick event?

I tried

[code=php]
<a hre=”#”><img src=”back.gif” onClick=”javascript:window.location.href=”main.jsp”></a>

** java script is javascript, not sure why it’s like that here **
[/code]

but it does not work.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisJun 17.2004 — &lt;a hre[color=red]f[/color]="#"&gt;&lt;img src="back.gif" onClick="window.location.href=[color=red]'[/color]main.jsp[color=red]';return false[/color]"&gt;&lt;/a&gt;
Copy linkTweet thisAlerts:
@JonaJun 17.2004 — [font=arial]Hello camokat, you might want to try using the following code.[/font]

<i>
</i>&lt;a href="main.jsp" onclick="return false;"&gt;
&lt;img src="back.gif" onclick="location.href='main.jsp';"&gt;
&lt;/a&gt;


[font=arial]Though, you could just as easily use the following and it would work on more browsers.[/font]

<i>
</i>&lt;a href="main.jsp"&gt;
&lt;img src="back.gif"&gt;
&lt;/a&gt;


[font=arial]Edit: Gil beat me by a hair![/font]
Copy linkTweet thisAlerts:
@camokatauthorJun 17.2004 — well strange thing with <a href="main.jsp">a</a>. On my computer it works fine, but on my co-worker's computer I get redirected to main.jsp but the url that is displayed is that of the pages where I was redirected from. We are running same OS and same browsers. Not sure why this is happening.
Copy linkTweet thisAlerts:
@JonaJun 18.2004 — [font=arial]Were you in a frameset on your co-worker's computer?[/font]
Copy linkTweet thisAlerts:
@camokatauthorJun 18.2004 — no, but there is an iframe in page...
Copy linkTweet thisAlerts:
@JonaJun 18.2004 — [font=arial]If the content and links are in an iframe, the URL in the addressbar will not change as the only URL changing is that of the iframe. ? [/font]
×

Success!

Help @camokat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...