В дальнейшем значение рассматривается как селектор, на котором находится фокус. () вызывается функция. Так, например, добавление ?focus=#search к базовому URL-адресу выделяет ввод с идентификатором «search».
Код: Выделить всё
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(document).ready(function() {
// Focus field specified in focus column
var selector = getParameterByName("focus");
$(selector).focus()
// Override submit functio
$("#search_form").submit(function(e) {
$("#output").text("submitting");
var form = $(this);
var url = form.attr('action');
$.ajax({
type: "POST",
url: url,
data: form.serialize(),
// serializes the form's elements.
success: function(data) {
$("#output").text(data);
}
});
e.preventDefault(); // avoid to execute the actual submit of the form.
});
});
Код: Выделить всё
https://example.org/?focus=Код: Выделить всё
https://example.org/?focus=#search").focus(function(){alert(1)});).focus()Код: Выделить всё
https://example.org/?focus=#search").attr('onFocus', 'alert(1)').focus();Я искал в Google приемник селектора JQuery, но не нашел ничего полезного. Подскажите пожалуйста, что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/790 ... lector-ctf
Мобильная версия