MVC.Net HTML Encoding, IE7 vs other browsers - urlencode

When I have this in my view
<a href="../Product/Category/<%= Html.Encode(item.Category) %>/Default.aspx?partial=False">
<%= Html.Encode(item.Category)%></a>
It renders as expected in IE8 & FF
<a href="../Product/Category/Sauces%20&%20Toppings/Default.aspx?partial=False">
Sauces & Toppings</a>
but does not render correctly in IE7
<a href="../Allergen/Category/Sauces & Toppings/Default.aspx?partial=False">
Sauces & Toppings</a>
Specifically, it appers IE7 is decoding the href property value.
How do I get IE7 to render the encoded href?

You're using the wrong encoding.
You need to call Html.AttributeEncode(Url.Encode(item.Category)).

Related

Upload file using selenium vba

I am using selenium vba and on the webpage there is an element that is supposed to enable me to upload a file. Here's the html for that element
<input type="file" name="attachments" id="attachments" accept=".pdf" maxlength="20" class="inputTextBox2">
I tried both methods to click on the element but the element doesn't respond at all
bot.FindElementById("attachments").Click
and
bot.ExecuteScript "arguments[0].click();", .FindElementById("attachments")
but both methods don't work and the element doesn't respond
Solved as I discovered that the input is a textbox so I used SendKeys to send the path
.FindElementByCss(".inputTextBox2").SendKeys THEFILEPATH

angular2 bootstrap4 tooltip doesn't render html, while popover does

I'm using angular2 and bootstrap4. Popover correctly renders raw html as bold text asdf
<img src="assets/images/1.jpg"
data-container="body" data-toggle="popover" data-html="true" data-placement="top"
[attr.data-content]="getM()"/>
However, tooltip renders as plain <b>asdf</b> text including tags
<img src="assets/images/2.jpg"
data-container="body" data-toggle="tooltip" data-html="true" data-placement="top"
[attr.title]="getM()"/>
Component method getM:
public getM(): string {
return '<b>asdf</b>';
}
Both tooltip and popover are initialized the same way
$(function () {
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
$('[data-toggle="popover"]').popover({container: 'body'});
})
Could someone explain why is that and how to solve? It seems this is connected with initialization order, but I just don't know where to look further.
Well, the issue was that my element (which tooltip was attached to) was created dynamically.
In exact, I had a 1 sec delayed service. When new data arrived, the <img> element in my component was recreated, but $('[data-toggle="tooltip"]') selector doesn't work with dynamic elements.
Instead, I had to use this selector
$("body").tooltip({selector: '[data-toggle="tooltip"]'});
Now it works as intended.
PS I'm not a front-end developer, so anyone who can explain it in better terms is welcome.

How to get elm to display HTML from an ajax call

I have the following Elm code, it is doing an Ajax call which will return some HTML which I want to embed directly into the dom. The problem is that the code here escapes the html so the user sees the markup, not the intended result. So I need to replace plainText with something else, but I am at a loss as to what that would be
load_comp_from_comp_set : String -> Signal Element
load_comp_from_comp_set compset_id =
Signal.constant ("http://localhost:8000/finch/compset/" ++ compset_id)
|> Http.sendGet
|> Signal.map (result >> plainText)
You can use Markdown.toElement from the elm-markdown library. I tried this the following code on elm-lang.org/try and it injected the HTML as expected.
import Markdown
main = Markdown.toElement """
<div>
<h1 style="display: inline">Hello!</h1>
<span></span> <sub>world</sub>
</div>
"""
You can use elm-package to install the library so elm-make automatically picks it up. It should be as simple as elm-package install evancz/elm-markdown.

How to prevent CKEditor insertHtml to wrap element within <p> in webkit browsers?

Im trying to build a front-end page to allow my users to build smarty templates with ckeditor wysiwyg editor.
Im using the insertHtml function to add a button with special attributes (needed to parse it into an smarty variable in the back-end):
// initialize ckeditor
$('textarea.editor').ckeditor({
contentsCss: '/css/test.css'
});
// get ckeditor instance
ckeditorInstance = $('textarea.editor').ckeditorGet();
// Use some elements (outside the textarea) to add buttons/tokens
// to wysiwyg textarea
$("a.tinymce.tinymce-insert-var").click(function(){
ckeditorInstance.insertHtml(
'<input type="button" readonly="readonly" var="{$user->name}" '
+ 'class="placeholder" value="User Name" />'
);
});
This works fine on Firefox, IE8 and opera, but with Chrome/Chromium/Safari the button is inserted between a <p> element.
Is there a way to avoid this, or a callback that i can use to remove the paragraph?
I had this problem as well. This is how I did it...
var editor = $('textarea[name=content]').ckeditorGet();
var element = CKEDITOR.dom.element.createFromHtml( '<p>I am a new paragraph</p>' );
editor.insertElement( element );
Looks like you're using jQuery also... why don't you force the inclusion of the p tag within CKEditor's .insertHtml function, then follow it up with jQuery's .unwrap to always remove the p tags?
in the main ckeditor config-file there is an option to disable automatic <p> inserts.
try to change the value of CKConfig.EnterMode and CKConfig.ShiftEnterMode for example to 'br'.
Felix

dojo.query not working for attribute selector that includes a tilde (~) character

I need to select a link node given its url. Using an attribute selector works quite well except for a few rare cases when the url has a tilda. I have no control over the link urls. Here is an example:
<script>
dojo.ready(function() {
var node = dojo.query('a[href="http://abc.com/~123"]')[0];
console.debug(node);
node = dojo.query('a[href="http://abc.com/_123"]')[0];
console.debug(node);
});
</script>
...
<body>
<a href="http://abc.com/~123">link 1</a>
<a href="http://abc.com/_123">link 2</a>
</body>
This prints:
undefined
<a href="http://abc.com/_123">
I looked at the level 3 selectors spec and didn't find anything on the tilde character being unsupported for attribute selector values which are just CSS strings.
Help!
This appears to have been fixed in 1.6 http://bugs.dojotoolkit.org/ticket/10651