简体   繁体   中英

Write current page URL into anchor tag for microdata

I am trying to use jquery to write the current page's URL into an anchor tag, that I can then tag for schema.org microdata. Here's what I got so far:

<script type="text/javascript">var url = document.URL;document.write(url);</script>

This writes the current page's url onto the page, however it is not in an anchor tag, and that tag does not include the proper microdata label of: itemprop="url"

Here is an example of the anchor tag I hope to achieve:

<a href="http://example.com/product" itemprop="url" />

I've tried searching around for a solution, but I simply do not know the programming language to accomplish this task. Any help would be appreciated!

Thanks - Alex

$('body').append($("<a itemprop='url' />").attr('href',document.URL).text(document.URL));

Demo ---> http://jsfiddle.net/kLu7j/

Or -

$('body').append($("<a/>",{
    href: document.URL,
    text: document.URL,
    itemprop:'url'
}));

Demo --> http://jsfiddle.net/kLu7j/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM