Javascript syntax for external js file


#1

This resource looks quite useful for identifying the environment that the app is running in. I hope you agree.
The API seems quite comprehensive.

https://frubil.info/

Using their example I can run this in Dreamweaver exactly as is and it reports correctly.

<script type="text/javascript" src="https://js.frubil.info/"></script>

<SCRIPT type='text/javascript' language='javascript'>

if(FRUBIL.status.value == 1) {
  document.write('Class: ' + FRUBIL.client.class + '<br />');
  document.write('Name: ' + FRUBIL.client.name + ' ' + FRUBIL.client.version + '<br />');
  document.write('OS: ' + FRUBIL.client.os + '<br />');
  document.write('Device class: ' + FRUBIL.device.class + '<br />');
  
  if(FRUBIL.client.isOs('Windows XP', 'Windows 98')) {
  	document.write('OS is Windows XP or Windows 98 <br />');
  }
  else {
  	document.write('OS is not Windows XP or Windows 98 <br />');
  }
  if(FRUBIL.device.isClass('Game console')) {
  	document.write('Device class is Game console <br />');
  }
  else {
  	document.write('Device class is NOT Game console <br />');
  }
} 
</SCRIPT>

I have tried to run this in NSB but have been unsuccessful.
Q1
How do implement this line to reference the external js resource file.
<script type="text/javascript" src="https://js.frubil.info/"></script>

I think if I can get that sorted the rest of the code may work.
I just cannot find any info in the documentation about how to do that.

frubil.nsx (17.6 KB)
frubil-example.zip (5.3 KB)


#2

Put this into Project Properties:

<script type="text/javascript" src="https://js.frubil.info/"></script>

Put the rest (without the <script> tags) anywhere in your project, in a JavaScript module.


#3

forgive me but where in Project Properties should it go?

I tried putting in Manifest and Script but neither is correct and throws an error.


#4

Whoops - forgot a key word. Put it in ‘extraheaders’.


#5

Brilliant - Thank you, works a treat.

I’m guessing that the information this utility provides is more than we can get by other means e.g.SysInfo. ??

This is the API
https://frubil.info/api_reference.html


#6

This information can be gotten in other ways, but the library does make it convenient.

Type navigator.userAgent into the Chrome console. You’ll get back a string which has most of the same information:

> navigator.userAgent
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36"

#7

Problem is, as I understand it, the Chrome console is not always (or readily) accessible in the app.

The simple demo I have attached makes it easy to identify the type of platform hosting the app.
Hope some find it useful.

frubil.nsx (16.8 KB)

Sysinfo alternative


#8

I only suggested using the Chrome Console as an easy way to look at that string.

You can also use it in your code.