Reputation: 1
I am trying to create a button that will display browser details in a new document using javascript. I have searched here and w3schools and am quite stumped! I am really new to javascript so any advice is greatly appreciated. Thanks!
<html>
<head>
<script type="text/javascript">
function docOpen()
{
document.open();
document.write(browserDetails);
}
function browserDetails () {
var x = navigator
document.write("CodeName=" + x.appCodeName)
document.write("<br />")
document.write("MinorVersion=" + x.appMinorVersion)
document.write("<br />")
document.write("Name=" + x.appName)
document.write("<br />")
document.write("Version=" + x.appVersion)
document.write("<br />")
document.write("CookieEnabled=" + x.cookieEnabled)
document.write("<br />")
document.write("CPUClass=" + x.cpuClass)
document.write("<br />")
document.write("OnLine=" + x.onLine)
document.write("<br />")
document.write("Platform=" + x.platform)
document.write("<br />")
document.write("UA=" + x.userAgent)
document.write("<br />")
document.write("BrowserLanguage=" + x.browserLanguage)
document.write("<br />")
document.write("SystemLanguage=" + x.systemLanguage)
document.write("<br />")
document.write("UserLanguage=” + x.userLanguage)
}
</script>
</head>
<body>
<form>
<input type="button" onclick="docOpen()" value="Get Browser Details">
</form>
</body>
Upvotes: 0
Views: 58
Reputation: 183
You can do something like
<html>
<head>
<script>
function docOpen()
{
document.open();
document.write(browserDetails()); // ADD '()' to call the function
}
function browserDetails () {
var x = navigator;
// iterate through all properties and get the values
for(var prop in x) {
document.write(prop+' = '+ x[prop]+'<br />');
}
}
</script>
</head>
<body>
<form>
<input type="button" onclick="docOpen()" value="Get Browser Details">
</form>
</body>
EDIT based on @Barmar comment
<script>
function docOpen()
{
document.open();
browserDetails(); // ADD '()' to call the function --
}
function browserDetails () {
var x = navigator;
// iterate through all properties and get the values
for(var prop in x) {
document.write(prop+' = '+ x[prop]+'<br />');
}
}
</script>
Upvotes: 0
Reputation: 9253
The problem is that you aren't invoking either of the functions you've defined. The call to browserDetails
isn't a call, it's just a reference, and nothing is invoking the docOpen
function.
Change line 4 to document.write(browserDetails());
Then invoke docOpen docOpen()
You'll also need to fix the smart quote as instructed by duskwuff.
I made a working fiddle at: https://jsfiddle.net/87q1a0kn/
Upvotes: 1
Reputation:
You have a curly double quote in place of a normal (straight) double quote here:
document.write("UserLanguage=” + x.userLanguage)
^
This is causing a syntax error. Replace it with a straight quote.
Upvotes: 2