admin管理员组文章数量:1290265
Line 251, Column 117: character "&" is the first character of a delimiter but occurred as data.
…elf" href="/service/el-amp-sikring/">El & Sikring<!--<span>›</span>--></a></li>
Is there anyway that I can replace all "&" signs within the body, because these are given from the backend. So it is the & that is placed in the html?
*EDIT Im trying to validate my webpage, and there keep occurring errors and warnings about this "&" symbol in both javascript, html and so on, but ofc i dont wanna change my "&" symbols in the javascript, so what i try to attempt is to change every "&" symbol given by the frontend using umbraco v 4.7.1.1
*EDIT2
<ul id="nav">
<% foreach (var topItem in Content.CurrentLanguage.VisibleChildren) { %>
<% var topMenuItems = NodeLocator.GetNodeOfExactType<TopMenuItems>(topItem.Id); %>
<li class="<%= topMenuItems != null ? "hasDropdown" : "" %><%= NodeController.IsNodeDescendantOfNode(Content.Id, topItem.Id) ? " active" : "" %>">
<a href="<%= topItem.Url %>"><%= topItem.MenuTitle %></a>
<% if (topMenuItems != null) { %>
<div class="drop">
<div class="drop-holder">
<div class="drop-frame">
<div class="drop-content">
<div class="col-a">
<%= string.IsNullOrWhiteSpace(topMenuItems.LeftHeading) ? "" : "<strong>{0}</strong>".With(topMenuItems.LeftHeading) %>
<div class="holder">
<% foreach (var part in topMenuItems.LeftTargets.Split(1)) { %>
<ul>
<% foreach (var htmlLink in part) { %>
<li style="" class="" ><a target="_self" href="<%= htmlLink.Url %>"><%= htmlLink.Title %><!--<span>›</span>--></a></li>
<% } %>
<li style="display:none;"></li>
</ul>
<% } %>
</div>
</div>
<div class="col-b">
<%= string.IsNullOrWhiteSpace(topMenuItems.RightHeading) ? "" : "<strong>{0}</strong>".With(topMenuItems.RightHeading)%>
<div class="holder">
<% foreach (var part in topMenuItems.RightTargets.Split(2)) { %>
<ul>
<% foreach (var htmlLink in part) { %>
<li style="" class="" ><a target="_self" href="<%= htmlLink.Url %>"><%= htmlLink.Title %><!--<span>›</span>--></a></li>
<% } %>
<li style="display:none;"></li>
</ul>
<% } %>
</div>
</div>
<% if(topMenuItems.Image != null) { %>
<div class="col-c">
<div class="holder">
<div class="image-holder">
<img src="<%= uComponents.Core.uQuery.GetMedia(topMenuItems.Image.Value).Url() %>" class="superimg" width="214" height="150" alt="superimg" />
</div>
<a href="<%= topMenuItems.ImageLink.Url %>" class="getoffer"><%= topMenuItems.ImageLink.Title %></a>
</div>
</div>
<% } %>
</div>
</div>
</div>
</div>
<% } %>
</li>
<% } %>
Line 251, Column 117: character "&" is the first character of a delimiter but occurred as data.
…elf" href="/service/el-amp-sikring/">El & Sikring<!--<span>›</span>--></a></li>
Is there anyway that I can replace all "&" signs within the body, because these are given from the backend. So it is the & that is placed in the html?
*EDIT Im trying to validate my webpage, and there keep occurring errors and warnings about this "&" symbol in both javascript, html and so on, but ofc i dont wanna change my "&" symbols in the javascript, so what i try to attempt is to change every "&" symbol given by the frontend using umbraco v 4.7.1.1
*EDIT2
<ul id="nav">
<% foreach (var topItem in Content.CurrentLanguage.VisibleChildren) { %>
<% var topMenuItems = NodeLocator.GetNodeOfExactType<TopMenuItems>(topItem.Id); %>
<li class="<%= topMenuItems != null ? "hasDropdown" : "" %><%= NodeController.IsNodeDescendantOfNode(Content.Id, topItem.Id) ? " active" : "" %>">
<a href="<%= topItem.Url %>"><%= topItem.MenuTitle %></a>
<% if (topMenuItems != null) { %>
<div class="drop">
<div class="drop-holder">
<div class="drop-frame">
<div class="drop-content">
<div class="col-a">
<%= string.IsNullOrWhiteSpace(topMenuItems.LeftHeading) ? "" : "<strong>{0}</strong>".With(topMenuItems.LeftHeading) %>
<div class="holder">
<% foreach (var part in topMenuItems.LeftTargets.Split(1)) { %>
<ul>
<% foreach (var htmlLink in part) { %>
<li style="" class="" ><a target="_self" href="<%= htmlLink.Url %>"><%= htmlLink.Title %><!--<span>›</span>--></a></li>
<% } %>
<li style="display:none;"></li>
</ul>
<% } %>
</div>
</div>
<div class="col-b">
<%= string.IsNullOrWhiteSpace(topMenuItems.RightHeading) ? "" : "<strong>{0}</strong>".With(topMenuItems.RightHeading)%>
<div class="holder">
<% foreach (var part in topMenuItems.RightTargets.Split(2)) { %>
<ul>
<% foreach (var htmlLink in part) { %>
<li style="" class="" ><a target="_self" href="<%= htmlLink.Url %>"><%= htmlLink.Title %><!--<span>›</span>--></a></li>
<% } %>
<li style="display:none;"></li>
</ul>
<% } %>
</div>
</div>
<% if(topMenuItems.Image != null) { %>
<div class="col-c">
<div class="holder">
<div class="image-holder">
<img src="<%= uComponents.Core.uQuery.GetMedia(topMenuItems.Image.Value).Url() %>" class="superimg" width="214" height="150" alt="superimg" />
</div>
<a href="<%= topMenuItems.ImageLink.Url %>" class="getoffer"><%= topMenuItems.ImageLink.Title %></a>
</div>
</div>
<% } %>
</div>
</div>
</div>
</div>
<% } %>
</li>
<% } %>
Share
Improve this question
edited Aug 27, 2012 at 14:56
Simon Dragsbæk
asked Aug 27, 2012 at 13:44
Simon DragsbækSimon Dragsbæk
2,3993 gold badges31 silver badges54 bronze badges
1
- You want to perform the string replacement in JavaScript? – Sampson Commented Aug 27, 2012 at 13:45
3 Answers
Reset to default 8Nope: the JavaScript is run too late. By the time the JavaScript is run, the browser has already been forced to parse the ill-formed HTML. You'll need to fix the back-end.
Update: In your C#/ASP.NET code, change this:
<%= htmlLink.Title %>
to this:
<%= Server.HtmlEncode(htmlLink.Title) %>
in both places.
(See "HttpServerUtility.HtmlEncode Method (String)" in the .NET framework documentation on MSDN.)
You can use a regular expression in your IDE, back-end code or javascript to replace all "&"s that are not already followed by "amp;" with "&":
str.replace(/&(?!amp;)/g, '&')
If you need to do javascript, this replaces every & which has a space behind it.
document.body.innerHTML = document.body.innerHTML.split("& ").join("& ");
本文标签: javascriptReplace quotampquot with ampamp in bodyStack Overflow
版权声明:本文标题:javascript - Replace "&" with &amp; in body - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741472494a2380688.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论