Reputation: 300
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];
}
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.
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>
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!
Thanks!
Upvotes: 3
Views: 1831
Reputation: 4721
document.all is an old IE4 standard. You should be using document.getElementById()
I would recommend you leverage one of the common javascript libraries that will abstract the different browsers implementations.
Upvotes: 1
Reputation: 842
replace:
document.all['companyURL'].innerHTML = vars[0];
with:
document.getElementById('companyURL').innerHTML = vars[0];
Upvotes: 7
Reputation: 2906
document.all is not supported by mozilla/FF
you can just use document.getElementById("companyURL")
there
Upvotes: 6