使用FireFox扩展将URL从本地文件系统重定向到Internet [英] Redirect URL from local filesystem to internet with FireFox extension
问题描述
file:/// page
而不是 http:// domain / page
修改这些文件以包含完整的URL不是一个选项。
我试过使用Firefox扩展重定向的URL,但都没有工作,所以我尝试创建自己的扩展做同样的。到目前为止我发现的是,在标签的准备好事件触发之前,URL是不可访问的,但是指向没有完整路径的本地文件的页面始终是未初始化的。
这里是我的扩展脚本,几乎来自 https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs :
var tabs = require(sdk / tabs);
tabs.on('open',function(tab){
tab.on('ready',function(tab){
if(tab.url.indexOf(file:/ // $ page $)
tab.url = tab.url.replace(file://,https:// domain);
}
});
});
任何想法如何将页面从本地文件重定向到另一个位置?
最简单的方法是找到另一个StackOverflow答案... 获取地址栏的内容。使用该答案中的函数来检索URL,然后基于该URL进行重定向。所以我最终得到了以下结果:
$ $ p $ $ $ c $ var tab = require(sdk / tabs);
tabs.on('open',function(tab){
tab.on('activate',function(tab){
var {getMostRecentWindow} = require(sdk / window / );
var urlBar = getMostRecentWindow()。document.getElementById('urlbar');
if(urlBar.value.indexOf(file:/// page /)!= -1 ){
tab.url = urlBar.value.replace(file://,https:// domain);
}
});
}) ;
I have several PDF files on my computer that contain links to other pages. Those links, however, direct you to the local filesystem instead of the internet. I.e. clicking the link opens the browser and takes you to file:///page
instead of http://domain/page
.
Getting these files modified to include the full URL is not an option.
I tried using available Firefox extensions to redirect the URL, but none worked, so I tried creating my own extension to do the same. What I've found so far is that the URL isn't accessible until the tab's "ready" event fires, but a page referring to a local file without the full path is always "uninitialized."
Here's my extension script, almost straight from https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs:
var tabs = require("sdk/tabs");
tabs.on('open', function(tab){
tab.on('ready', function(tab){
if (tab.url.indexOf("file:///page") != -1) {
tab.url = tab.url.replace("file://", "https://domain");
}
});
});
Any ideas how to go about redirecting a page from a local file to another location?
The easiest way I've found to do this is actually from another StackOverflow answer... Get Content of Location Bar. Use the function in that answer to retrieve the URL and then redirect based on that. So I end up with the following:
var tabs = require("sdk/tabs");
tabs.on('open', function(tab){
tab.on('activate', function(tab){
var { getMostRecentWindow } = require("sdk/window/utils");
var urlBar = getMostRecentWindow().document.getElementById('urlbar');
if (urlBar.value.indexOf("file:///page/") != -1) {
tab.url = urlBar.value.replace("file://", "https://domain");
}
});
});
这篇关于使用FireFox扩展将URL从本地文件系统重定向到Internet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!