I think it is because chrome interprets it as an HTML element and you can click and get through.
As for other browsers I suppose you are not facing this issue so you can execute this piece of code only in chrome.
Look for Selenium API you there might be way to find browser type at run time.
~ seleniumtests.com