reference material for attributes of <a> and <img> tags
I am troubleshooting this line of code: e is of type image(img) and b is of type link(a). It seems to be concatenating the local host to e.src and not doing just a direct copy of the string.
Where is reference material located on the开发者_Python百科 Mozilla Development Network that lists object properties, particularly the .src property of my image?
You need to assign a proper href
attribute if you want to extract the hostname
.
Instead of:
<a href="www.ay.com">link</a>
you should do:
<a href="http://www.ay.com">link</a>
or at least:
<a href="//www.ay.com">link</a>
Then you'll be able to extract the hostname. Otherwise the browser assumes www.ay.com
is a local file or directory.
If for some reason you can't change the href
, then you'll need to use getAttribute()
to be able to retrieve it unmodified.
e.src=b.getAttribute('href');
If I'm not totally mistaken, that's a property of HTML links. If you have <a href="www.ay.com">
the link will point to http://example.com/www.ay.com
. In this case you probably want e.src = b.href
.
Probably your link is wrong. Use http://www.ay.com instead.
MDN Documentation refers to object properties as attributes, the relevant documentation for the attribute 'href' for the 'a' element is found here
精彩评论