ユーザーがリンクをクリックするのを待って、リンクをクリックするとリンクのテキストが取得される可能性はありますか?
多分onClickを使用して?
ユーザーがリンクをクリックするのを待って、リンクをクリックするとリンクのテキストが取得される可能性はありますか?
多分onClickを使用して?
ユーザーが閲覧しているページ内のリンクのクリック イベントを処理する場合は、次のようになります。
// handle the load event of the window
window.addEventListener("load",Listen,false);
function Listen()
{
gBrowser.addEventListener("DOMContentLoaded",DocumentLoaded,true);
}
// handle the document load event, this is fired whenever a document is loaded in the browser. Then attach an event listener for the click event
function DocumentLoaded(event) {
var doc = event.originalTarget;
doc.addEventListener("click",GetLinkText,true);
}
// handle the click event of the document and check if the clicked element is an anchor element.
function GetLinkText(event) {
if (event.target instanceof HTMLAnchorElement) {
alert(event.target.innerHTML);
}
}
これは、jQuery を使用すると非常に簡単です。
<script>
$(document).ready(function(){
$("a").click(function(){alert($(this).text());});
});
</script>
もちろん、テキストに警告する以外のことをしたいと思うでしょう。