有没有办法在JavaScript中检查字符串是否是URL?
RegExes被排除在外,因为URL最有可能写成stackoverflow; 也就是说它可能没有.com,www或者http.
我需要将For循环字符添加到空字符串中.我知道您可以在Javascript中使用函数concat来使用字符串进行连接
var first_name = "peter";
var last_name = "jones";
var name=first_name.concat(last_name)
Run Code Online (Sandbox Code Playgroud)
但以我的例子,它不起作用.知道如何以另一种方式做到这一点吗?
我的代码:
var text ="";
for (var member in list) {
text.concat(list[member]);
}
Run Code Online (Sandbox Code Playgroud) 我想开发一个Internet Explorer扩展程序,用于更改特定网页的内容,例如Google Chrome中的内容脚本.(例如,当我访问谷歌网站并搜索"汽车"时,我想在页面上创建一个带有"汽车"字样的div).
我一直在寻找,但没有找到明确的证据,如果这种事情是可能的.
我特别想要的是一个清晰的教程或如何做到这一点的一些例子.
布鲁诺,
我想从Google搜索的网址中提取搜索关键字(例如关键字"car":http://www.google.com/webhp?hl = zh_CN&sspient = psy&hl = en&site = webhp&source = hp&q = car&aq ...(这里的车位于"q ="和"&aq"之间,但我注意到令牌可能会改变["&ie"而不是"&aq"]).
作为正则表达式和谷歌搜索的新手我到目前为止还没有找到解决方案,有人知道如何做到这一点吗?
布鲁诺
我想更改网页的内容,以根据网页添加更改的元素.
例如,我想用文字"你是在显示一个div元素http://www.google.com "当用户在网站上http://www.google.com但是当用户进入到HTTP ://www.yahoo.com div应该改变并显示"你在http://www.yahoo.com上 ".
我正在寻找的是一些开头的例子(我希望不是第一个想到这种技巧的人).
如何使用Javascript获取HTML字符串的属性列表?到目前为止,这是我的代码.
function traverse_test(){
var root=document.getElementById('arbre0').childNodes;
for(var i=0;i<root.length;i++){
var lis = root[i];
if (lis =='[object HTMLUListElement]') {
for (var member in lis) {
if (typeof lis[member] == "string") {
var assertion = lis[member];
var resultat = assertion.search(/..Bookmarks/);
if (resultat != -1) {
output.innerHTML+= lis[member];
// Here I'd like to have the list of lis[member] attributes
for(var attr in lis[member].attributes) {
output.innerHTML+=lis[member].attributes[attr].name + "=\""+ lis[member].attributes[attr].value + "\"";
}
break;
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个Firefox扩展但我无法使用它(没有任何反应).有人知道为什么吗?
模块层次结构
my_firefox_extension
代码
chrome.manifest用于
content firefox_extension chrome/content/
overlay chrome://browser/content/browser.xul chrome://firefox_extension/content/sample.xul
Run Code Online (Sandbox Code Playgroud)
的install.rdf
<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>displaypages@bruno.com</em:id>
<em:name>Display the page locale</em:name>
<em:description>Welcome to this extension that displays the page locale when a user opens a new tab or windows</em:description>
<em:version>0.1</em:version>
<em:creator>Bruno Da Silva</em:creator>
<em:homepageURL>https://www.example.com</em:homepageURL>
<em:type>2</em:type>
<!-- Mozilla Firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.0</em:minVersion>
<em:maxVersion>4.0.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>
Run Code Online (Sandbox Code Playgroud)
sample.xul
<?xml version="1.0"?>
<overlay id="firefox_extension-browser-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://firefox_extension/content/overlay.js"/>
</overlay>
Run Code Online (Sandbox Code Playgroud)
overlay.js中
function …Run Code Online (Sandbox Code Playgroud) 我正在研究一个Gui,我想知道是否可以在我的脚本中将窗口的菜单属性设置为一个单独的类,以获得更清晰,更易于增强的代码.
我的代码目前是:
class Application(Frame):
""" main window application """
def __init__(self, boss = None):
(...)
self.menu = Menu(self)
self.master.config(menu = self.menu)
self.select = Menu(self.menu)
self.menu.add_cascade(label = 'Select', menu = self.select)
self.select.add_command(label = 'Select all', command = self.select_all)
...
Run Code Online (Sandbox Code Playgroud)
我更喜欢这样的东西:
class MenuBar:
# all the content of the menu here
class Application(Frame):
(...)
self.menu = MenuBar(self) ?
Run Code Online (Sandbox Code Playgroud)
RGDS,