jQuery:修复带有基标记的web链接
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery:修复带有基标记的web链接相关的知识,希望对你有一定的参考价值。
on using any wysiwyg editor (f.e. CKEditor) is inserted link to anchor on same page in this form: [a href="#anchor"]text[/a]if on web site is used tag BASE, anchors links are wrong - on all page are on this url: www.domain.com/#anchor
this function repair this anchor link to correct url
jQuery.repairLink2Anchor = function() { // exists tag BASE if ($("base").length) { // regular expression for anchor link var re1 = /#([w-]+)/; // anchor parts var re2 = /^#([w-]+)/; // only anchor // read current url var thisUrl = document.location.href; // remove anchor from current url thisUrl=thisUrl.replace(re1,""); // inicialization var href = ''; var anchor = ''; // loop all A tags whith attribute href $("a[href]").each(function(){ href = $(this).attr("href"); // check - href is anchor? if (re2.test(href)) { anchor = href.match(re2); $(this).attr("href", thisUrl + '#' + anchor[1]); } }); } } /* start this jQuery function with: $.repairLink2Anchor(); */
以上是关于jQuery:修复带有基标记的web链接的主要内容,如果未能解决你的问题,请参考以下文章