问题
I need to use XHTML strict
I need to ensure my site works with no javascript.
I need to open a new help window from my own application. Of course I wanted to use target="_blank" when no javascript detected but this is not XHTML strict.
Are there any alternatives?
回答1:
You have to use javascript in this case. If you don't want to use javascript, and still have valid markup, don't use XHTML Strict as your doctype.
document.getElementById("mylink").target = "_blank";
Or you can attach a click-event to the link that opens the address up in a new window. Either way, javascript is your solution if you want valid markup.
回答2:
You can only do this by:
- Use Transitional doctype
- or use JavaScript
Don't force new windows on visitors
回答3:
This is the easy way:
<a href="link" onclick="target='_blank'">link</a>
回答4:
<a href="http://www.google.com" onclick="this.target= '_blank';return true;" >Google</a>
回答5:
Actually, there may be a way to do this without javascript. You can write a custom DTD as described here.
Add a target attribute to your customization and it will validate. I just came up with this idea and I'm not sure if I'm missing any drawbacks.
回答6:
Try to use this:
http://www.webaddress.com' target='_blank'
as the address.
来源:https://stackoverflow.com/questions/1211928/alternative-to-target-blank-when-using-xhtml-strict-and-no-javascript