私はFirefoxの拡張機能を書いています。dom.location を使用して、訪問した検索結果ページを追跡し、この URL http://www.google.com/search?hl=en&source=hp&q=hi&aq=f&aqi=&oq=&fp=642c18fb4411ca2eを取得しています。クリックすると、「こんにちは」の Google 検索結果が表示されます。ページの残りの部分が読み込まれないため、タイトル バーからそれがわかります。これは、どの Google 検索でも発生します。奇妙なことに、http://www.google.com/search?hl =en& source=hp&q=hi のようにその一部を切り取ると、うまくいきます。しかし、「こんにちは」とグーグルで検索すると、長いURLが表示されます- http://www.google.com/#hl=en&source=hp&q=hi&aq=f&aqi=&oq=&fp=db658cc5049dc510。
誰かがこれを理由にすることができますか?
もう一度実験してみましたが、今回は元の URL をロケーション バーに保存しました。dom.location.href が別の値を与えていることが判明しました。これはどのように起こっていますか?
オリジナル:
http://www.google.com/#hl=en&source=hp&q=hi&aq=f&aqi=&oq=&fp=642c18fb4411ca2e
dom.location.href
http://www.google.com/search?hl=en&source=hp&q=hi&aq=f&aqi=&oq=&fp=642c18fb4411ca2e
window.addEventListener("load", function() { myExtension.init(); }, false);
var myExtension = {
init: function() {
var appcontent = document.getElementById("appcontent"); // browser
if(appcontent)
appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true);
var messagepane = document.getElementById("messagepane"); // mail
if(messagepane)
messagepane.addEventListener("load", function () { myExtension.onPageLoad(); }, true);
},
onPageLoad: function(aEvent) {
var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
// do something with the loaded page.
// doc.location is a Location object (see below for a link).
// You can use it to make your code executed on certain pages only.
var url = doc.location.href;
if (url.match(/(?:p|q)(?:=)([^%]*)/)) {alert("MATCH" + url);resultsPages.push(url);} else {alert(url);
}
}
このスニペットは、Mozillaから直接提供されており、独自のマッチングとアラートが含まれています。以前にコードを投稿しなかったことをお詫びします。