Firefox记录无效的URL?

时间:2009-11-06 22:15:16

标签: firefox dom firefox-addon location

我正在为firefox编写扩展程序。使用dom.location跟踪访问过的搜索结果页面,我得到了这个网址http://www.google.com/search?hl=en&source=hp&q=hi&aq=f&aqi=&oq=&fp=642c18fb4411ca2e。如果您点击它,谷歌搜索结果“hi”应该出现。你会从标题栏中知道 - 因为页面的其余部分不会加载。任何谷歌搜索都会发生这种情况。奇怪的是,如果你把它的一部分切掉了,那就说http://www.google.com/search?hl=en&source=hp&q=hi - 它有效!但谷歌搜索“嗨”我自己确实给了我一个很长的网址 - 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,其中包含匹配并提醒我自己。我很抱歉没有提前发布代码。

1 个答案:

答案 0 :(得分:0)

好吧,在“右侧”页面http://www.google.com/#hl=en&source=hp&q=hi&aq=f&aqi=&oq=&fp=1&cad=b上,似乎有一个框架的“错误”位置:frames [0] .location ==“http://www.google.com/search?hl=en&source=hp&q=hi&aq=f&aqi=&oq=&fp=1&cad=b”。你可能正在获得内部框架的位置。我不知道为什么,因为你没有发布任何代码,只提一些我从未听说过的“dom.location”。

相关问题