I have alert boxes all around my site, that have been working up until now, ( I have done a few updates to my blog recently before this started happening ) the problem I am experienceing is that when I click on a link ( in my case a image link ) and the alert box appears, I submitt the ok button and suddenly im rediercted to a white page with 'true' in the top corner. My alert box scripts are inside my blog template.
I tested this alert box script out i开发者_JS百科n a blog post:
<"a href="javascript:onClick=alert("Not an active link");">CLICK<"/a>
withouth the extra "
and then went to preview the post, however the same error occured. This is not a browser problem as it only happens on my site, when i got to someone elses with alert boxes, it works. Please help with this I have been asking about it for about a week now and would appreciate someone who can help
here is a screenshot of what I get redirected to:
http://img813.imageshack.us/img813/2674/true.pngThanks for all help.
Use this
<a href="javascript:onClick=alert('Not an active link');">CLICK</a>
Demo here: http://jsfiddle.net/e2fkT/embedded/result/
I think you have some typos... It would be:
<a href="javascript:onclick=alert('Not an active link');">click</a>
Use simple quotes inside or escape double quotes.
I don't understand the use of onclick there too... Just the alert will open an alert box when you click.
<a href="javascript:alert('Not an active link');">click</a>
Also it would be better to separate javascript from html... You could include with the following content (jquery example, i forgot almost everything about old javascript... just get the idea) into a non-active-links.js file or in a block:
$(document).ready(function () {
$('a.non-active-link').click(function () {
window.alert('Not an active link');
return false;
});
});
That way all links in the page with a class attribute of "non-active-link" will fire up the alert box.
I think you messed up with javascript inside href and the onclick attribute. Your snippet is actually assigning the result of the alert
function call to the variable onCLick
. The display of true might be the return value of the alert
method. Still an odd behavior.
<a href="javascript:alert('Not an active link');">CLICK</a>
<a href="#" onclick="alert('Not an active link');">CLICK</a>
Those two cause no problems to me.
精彩评论