Validating iFrame when called by Javascript onclick
I'm trying to validate the following code (Inside a 开发者_JS百科XHTML transitional doc):
<a href="#" onclick="document.getElementById('courseFrameBottomRight').innerHTML = '<iframe src=\'descriptions/bf_isc.html\' scrolling=\'no\' frameborder=\'0\'></iframe>'" id='onClickTextChange2'><span class="title">Website</span></a>
However, this is throwing a huge number of validation errors.
Example:
Line 168, Column 98: character "<" is the first character of a delimiter but occurred as data
The code is modified from a help guide and I don't have experience with the nested quoting or back-slashing going on here. Can someone offer some quick syntax pointers for me to get this valid for XHTML Transitional? Thanks!
Try backslashing the '<' '>' signs, like '\<iframe\>'
If it doesn't work use the html code instead:
>
for >
<
for <
<iframe>
So the only phrase would be something like:
<a href="#" onclick="document.getElementById('courseFrameBottomRight').innerHTML = '\<iframe src=\'descriptions/bf_isc.html\' scrolling=\'no\' frameborder=\'0\'\>\<\/iframe\>'" id='onClickTextChange2'><span class="title">Information Systems Clinic</span></a>
or
<a href="#" onclick="document.getElementById('courseFrameBottomRight').innerHTML = '<iframe src=\'descriptions/bf_isc.html\' scrolling=\'no\' frameborder=\'0\'></iframe>'" id='onClickTextChange2'><span class="title">Information Systems Clinic</span></a>
Or better yet, create a javascript function that does what you need outside the html body code.
Try replacing your brackets < > with the escape characters < and > Paste your whole iframe string into this page and it will give you the escaped equivalent of it: http://www.htmlescape.net/htmlescape_tool.html
That link will give you something like this <iframe src=\'descriptions/bf_isc.html\' scrolling=\'no\' frameborder=\'0\'></iframe> and that will validate.
edit: I see you got this answer. Just use the above tool to do your escaping for you so it's easy.
精彩评论