久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 Chrome 中的 dragstart 事件中獲取所選項(xiàng)目

How do you get the selected items from a dragstart event in Chrome? Is dataTransfer.getData broken?(如何從 Chrome 中的 dragstart 事件中獲取所選項(xiàng)目?dataTransfer.getData 壞了嗎?)
本文介紹了如何從 Chrome 中的 dragstart 事件中獲取所選項(xiàng)目?dataTransfer.getData 壞了嗎?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我是一個(gè)開發(fā) Java 應(yīng)用程序的團(tuán)隊(duì)的一員,該應(yīng)用程序可以幫助人們組織和注釋來自網(wǎng)絡(luò)的信息.我們目前使用一個(gè) Firefox 插件,它附加了一個(gè)包含文檔源的容器屬性,它允許拖動(dòng)的文本被自動(dòng)引用.這并不總是導(dǎo)致獲取源文檔,因?yàn)樵谶x擇不跨越HTML標(biāo)記時(shí)才會(huì)傳輸文本.例如

I am part of a team that works on a Java application that, among other things, helps people organize and annotate information from the web. We currently use a Firefox plug-in that attaches a container attribute that contains a document source, which allows dragged text to become cited automatically. This will not always result in getting the source document because only text is transferred when a selection does not cross html tags. e.g.

<p container="http://www.somesite.com/blah.html">this is text from a site</p><p container="http://www.somesite.com/blah.html">this is more text from a site</p>

所以如果只選擇了is text,html標(biāo)簽永遠(yuǎn)不會(huì)交叉,瀏覽器會(huì)認(rèn)為環(huán)繞標(biāo)簽信息及其容器屬性是不需要的;所以它會(huì)忽略它.

So if only is text is selected, the html tags are never crossed and the browser thinks the surround tag information and its container attribute would be unwanted; so it ignores it.

因此,我決定制作一個(gè) Chrome 擴(kuò)展程序,該擴(kuò)展程序?qū)⒗?HTML5 的一些漂亮特性,使從瀏覽器頁面拖放到 Java 應(yīng)用程序中的任何拖動(dòng)都包含源文檔.僅供參考,Chrome 擴(kuò)展是基于 Javascript 的.

So I decided to make a Chrome extension that would exploit some of the nifty features of HTML5 to make any drag from a browser page that is dropped into out Java application include the source document. FYI, Chrome extensions are Javascript based.

看來,正確的做法是在文檔上注冊(cè)一個(gè) dragstart 事件,這將允許我訪問拖動(dòng)的內(nèi)容并讓我注入一個(gè)包含源文檔位置的元標(biāo)記.

The correct for thing to do, it seems, is to register a dragstart event on the document that will allow me to access the content of the drag and also let me inject a meta tag that includes the source document location.

根據(jù)現(xiàn)行標(biāo)準(zhǔn),http://dev.w3.org/html5/spec/Overview.html#the-datatransfer-interface ,這應(yīng)該可以通過使用 dataTransfer 接口來實(shí)現(xiàn).

According to the current standard, http://dev.w3.org/html5/spec/Overview.html#the-datatransfer-interface , this should be possible by using the dataTransfer interface.

所以,我注冊(cè)了 dragstart 事件,它應(yīng)該給我 dataTransfer 事件信息.您可以將此代碼復(fù)制并粘貼到 Chrome 的 Javascript 控制臺(tái)中以親自查看:

So, I register the dragstart event that should give me the dataTransfer event information. You can copy and paste this code into Chrome's Javascript console to see it for yourself:

window.addEventListener("dragstart", function(event) {
console.log(event.dataTransfer.types);
console.log(event.dataTransfer.getData("Text"));     });

然后選擇一些東西并拖動(dòng)它.在 Chrome 中,輸出是 "null" 然后是 "undefined".如果您將相同的代碼粘貼到 Firebug 的 Javascript 控制臺(tái),然后拖動(dòng)一些您選擇的文本,輸出就是您所期望的:

Then select something and drag it. In Chrome, the output is "null" then "undefined". If you paste the same code into Firebug's Javascript console then drag some text that you select, the out put is what you would expect:

DOMStringList { 0="text/_moz_htmlcontext", 1="text/_moz_htmlinfo", 2="text/html", more...}
whatever text was selected

奇怪的是,可以在 event.dataTransfer 上使用 setData 來更改丟棄的內(nèi)容.這部分似乎按預(yù)期工作.將其粘貼到 Chrome Javascript 控制臺(tái)中,然后選擇一些內(nèi)容并將其拖到文本編輯器或您的搜索框中:

Curiously, one can use setData on the event.dataTransfer to change what is dropped. That part seems to work as expected. Paste this instead into the Chrome Javascript console, then select something and drag it to a text editor or your search box:

window.addEventListener("dragstart", function(event) {
    event.dataTransfer.setData("Text","I made this here for you!");
});

它看起來像壞了.:( 有沒有人有解決方法或?qū)Υ藛栴}有所了解?我真的希望它在 Chrome 中工作,因?yàn)槲蚁矚g它的擴(kuò)展架構(gòu).

It looks like it's broken. :( Does anyone have a workaround or some insight into this issue? I really want this to work in Chrome because I like its extension architecture.

謝謝!

推薦答案

WebKit 和 Chrome 對(duì)何時(shí)可以調(diào)用 getData 有很大的限制.你不能在 dragstartdragstart代碼>dragover.我認(rèn)為這是典型的錯(cuò)誤.

WebKit, and hence Chrome, is quite restrictive on when you can call getData. You're not allowed to do it inside dragstart or dragover. I think this is the canonical bug.

這篇關(guān)于如何從 Chrome 中的 dragstart 事件中獲取所選項(xiàng)目?dataTransfer.getData 壞了嗎?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認(rèn)為文檔“準(zhǔn)備好之前,如何讓我的 jasmine 測(cè)試裝置加載?) - IT屋-程序員軟件開發(fā)技術(shù)
What do jasmine runs and waitsFor actually do?(jasmine 運(yùn)行和等待實(shí)際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測(cè)試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對(duì)鏈?zhǔn)椒椒ㄟM(jìn)行單元測(cè)試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測(cè)試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監(jiān)視函數(shù)中的函數(shù)調(diào)用?)
主站蜘蛛池模板: 日本成人久久 | 久久成| 国产精品视频网址 | 97在线观视频免费观看 | 久热国产精品视频 | 国产欧美日韩 | 狠狠久久 | 日韩一区二区三区在线视频 | 欧美日韩亚洲视频 | 国产精品人人做人人爽 | 中文字幕av在线播放 | 久久久激情 | 欧美日产国产成人免费图片 | 免费一区二区在线观看 | 成人性视频免费网站 | 中文字幕国产高清 | 亚洲一区视频在线 | 天堂资源最新在线 | 国产午夜精品一区二区三区嫩草 | 一区二区精品 | 欧美色性 | 久久99精品久久久水蜜桃 | 天天射影院 | 91精品国产乱码麻豆白嫩 | 中文字幕av亚洲精品一部二部 | 日韩和的一区二区 | 日本aⅴ中文字幕 | 久久久久久九九九九九九 | 亚洲国产成人精品一区二区 | 亚洲精品成人 | 亚洲精品乱码久久久久久蜜桃91 | 国产香蕉视频 | 精品一区二区在线视频 | 日本a网站 | 亚洲精品一区二区在线观看 | 拍真实国产伦偷精品 | 免费黄色的视频 | 男女网站免费 | 亚洲欧美日本在线 | 奇米影视首页 | 欧美成人一区二区 |