错误在Firefox中的JavaScript
我在Firefox中运行JavaScript时遇到问题。下面的脚本在Firefox以外的其他浏览器中运行时没有问题。
I have a problem with JavaScript running in Firefox. The script below runs without a problem in other browsers except Firefox.
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[i]] = hash[1];
}
if (vars[0] != ' ')
{
document.all['companyURL'].innerHTML = vars[0];
document.getElementById('domain').value = vars[0];
}
所以这段代码在页面加载期间运行,应该抓取URL后面的值
So this code runs during page load and should grab the values after the URL and replace a line of text in the page with whatever is in the URL.
这是需要替换的文本行(yourcompany.com):
This is the line of text it needs to replace (yourcompany.com):
<h1><a href="" id="companyURL" name="companyURL">yourcompany.com</a> is available.<img src="images/checkmark_64.png" alt="check image"></h1>
因此,如果网址是google.com?hello.com,那么网页中的文字需要从yourcompany.com更改为hello.com,但是当Firefox加载页面时,它会给出错误信息 document.all is undefined 并指向代码行
$ b
So if the url is "google.com?hello.com", then the text in the page needs to change from "yourcompany.com" to "hello.com", but when the page loads in Firefox, it gives me the error "document.all is undefined" and points to the line of code with this in it.
document.all['companyURL'].innerHTML = vars[0];
我不知道为什么会发生这种情况,我无法在网上找到任何可以帮助我的信息纠正问题。请帮助!
I have no idea why this is happening and I can't find any information online that can help me correct the issue. Please help!
谢谢!
replace:
document.all['companyURL'].innerHTML = vars[0];
附带:
with:
document.getElementById('companyURL').innerHTML = vars[0];