本文介绍了在Stackoverflow上的关闭弹出窗口中插入链接到欺骗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一些代码,在SO关闭问题弹出窗口中插入一个欺骗的链接:

I'm working on some code to insert a link to a dupe in the SO close question popup:

当您在文本框中手动插入问题的链接时会发生什么JS开始并提取属于URL的问题。但是,当我使用javascript(Chrome扩展程序)将URL插入文本框时,SO javascript从未启动以检索问题。我用来插入欺骗网址的代码是:

What happens when you manually insert a link to a question in the textbox is that some JS kicks in and fetches the question belonging to the URL. However when I insert an URL using javascript (Chrome extension) into the textbox the SO javascript never kicks in to retrieve the question. The code I am using to insert the URL of the dupe is:

$(document).on('click', '.cvhelper-dupelist li', function() {
  var url = $('a', this).attr('href');
  var $dupeBox = $('#duplicate-question');

  $dupeBox.val(url);
});

上面的代码成功地在文本框中插入了链接,但由于某种原因,SO javascript从未踢过检索问题。

The above code successfully inserts the link in the textbox, however for some reason the SO javascript never kicks in to retrieve the question.

我也尝试过以下措施,但可能无法使用:

I've also tried the following to maybe force it to no avail:

$dupeBox.change();

$dupeBox.keyup();

要测试发生了什么,你可以打开关闭随机弹出(如上所述)随机问题并运行:

To test what is happening you could open up the close as dupe popup (as above) of a random question and run:

$('#duplicate-question').val('http://stackoverflow.com/questions/8028957/headers-already-sent-by-php');

推荐答案

我想我想出了一种方法,但它相当脆弱:

I think I figured out one way, but it's rather fragile:

$dupeBox.data('events').keydown[1].handler({keyCode: 13})

此触发器此元素的第二个keydown事件处理程序。并为存根事件对象提供了一个keyCode。

This triggers the second keydown event handler of this element. And gives a keyCode for the stubbed event object.

更新

找到了更好的方法:

你可以构建一个对象:

var e = jQuery.Event("keydown", { keyCode: 64 });

并使用此对象触发事件:

And trigger the event with this object:

$dupeBox.trigger(e)

问题是SO代码检查事件对象中是否有东西:

The problem was that the SO code checked whether there was something in the event object:

e(d).keydown(c).bind("paste", null, function(a) {
  a.which || c(this)
})

这篇关于在Stackoverflow上的关闭弹出窗口中插入链接到欺骗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 20:40