Using online and href within a link

For technical support for all editions of CSE HTML Validator. Includes bug reports.

Using online and href within a link

Postby ajtruckle » Sat Feb 27, 2010 4:25 pm

Hello again

I have this code:

Code: Select all
(<a href="privacy.html" onclick="popUpWin(this.href,'console3',610,210);return false;" target="popUpWin" title="View our privacy policy">Privacy Policy</a>)

To be honest, it is something that I scoured from the internet several months ago. It uses javascript to popup the url. As far as I am aware this is working fine in IE8, Safari and Firefox. I don't know about other browsers. But the validation result said:

Using both "href" and "onclick" attributes with an "a" tag may be problematic because of how it may work. Typically, the "onclick" event would be executed first, then the "href" would take effect, but miscellaneous issues may occur with different browsers and different user settings (such as whether scripting is on). If using both attributes, then perform testing on a variety of browsers and settings to make sure it works as intended.

From your description it should behave as I require. I don't know of any other way to show a popup window.
ajtruckle
Rank II - Novice
Rank II - Novice
 
Posts: 44
Joined: Sat Feb 27, 2010 2:24 pm

Re: Using online and href within a link

Postby ajtruckle » Sat Feb 27, 2010 5:51 pm

OK, I think I have come up with a suitable solution that would not cause compliance warnings.

Code: Select all
<html>
<body>
<p>start of page</p>
<script type="text/javascript">
document.write("<a href=\"javascript:window.open('http://www.microsoft.com','name','height=400,width=200')\">Click here A</a>");
</script>
<noscript><a href="http://www.microsoft.com">Click here B</a></noscript>
<p>rest of page</p>
</body>
</html>

Basically, I add some javascript to write the popup link syntax into the html file. If javascript is switched off then it uses the noscript property and inputs a regular hyperlink. I guess I could change the target to a new window to atleast leave the current page intact.

I think that is the best solution and it avoids using href and onclick and still supports non-javascript browsers.

Andrew
ajtruckle
Rank II - Novice
Rank II - Novice
 
Posts: 44
Joined: Sat Feb 27, 2010 2:24 pm


Return to CSE Tech Support

Who is online

Users browsing this forum: No registered users and 2 guests