admin管理员组文章数量:1332383
I need to add link rel tags to the head tag dynamically based on what page is being loaded. Is there a way to do this using the page.header.controls.add method? or is it only possible through javascript or jquery? Thanks in advance for the help.
I need to add link rel tags to the head tag dynamically based on what page is being loaded. Is there a way to do this using the page.header.controls.add method? or is it only possible through javascript or jquery? Thanks in advance for the help.
Share Improve this question asked Dec 1, 2014 at 5:53 ManiMani 3791 gold badge5 silver badges22 bronze badges 3- would probably be best to do this server side with whatever CGI programming language you prefer. In this case you'll use ASP. – Rafael Commented Dec 1, 2014 at 5:57
- thanks for the reply, i am a newbie, could you please elaborate? much appreciated – Mani Commented Dec 1, 2014 at 6:00
- 1 I say it is best to use server side for this because if a request is made by a user you want the server to process the output before the user gets it. This would make more sense to do in a server language in my opinion. – Rafael Commented Dec 1, 2014 at 6:40
3 Answers
Reset to default 3You can use HtmlGenericControl class for this:-
HtmlGenericControl linkFile = new HtmlGenericControl("link");
linkFile.Attributes.Add("rel", "canonical");
linkFile.Attributes.Add("href", "testPath");
Page.Header.Controls.Add(linkFile);
Can you try this
if(!document.getElementById('id2')) {
var link = document.createElement('link');
link.id = 'id2';
link.rel = 'stylesheet';
link.href = 'CSS/Css1.cs';
document.head.appendChild(link);
}
We can also use this:
HtmlLink clink = new HtmlLink();
clink.Attributes.Add( HtmlTextWriterAttribute.Rel.ToString().ToLower(), "canonical");
clink.Href = "http://www.test.co.in/";
Page.Header.Controls.Add(clink);
本文标签: javascriptadd a ltlink relquotcanonicalquot dynamically in the head tagStack Overflow
版权声明:本文标题:javascript - add a <link rel="canonical" dynamically in the head tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742287804a2447244.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论