1

I'm trying to import the image of multiple IP cameras into one page. However, the script the camera serves for the viewer has the same name on every camera so i cannot seem to display both the viewers on one page. Would it be possible to import the scripts with a sort of AS alias so it knows which of the 2 scripts to execute?

In the below pseudo-code I show what i exactly mean (i made up the AS="cam1" and the cam1.~~)

<html>
<head>
        <title>Security Cameras</title>
</head>
<body>
        <script AS="cam1" type='text/javascript' src='http://192.168.1.10:80/jsv/SncViewer.js'></script><script>cam1.SNC.writeViewer({sz:'4',ptz:'1',fps:'15',iPS:'1'})</script>
        <script AS="cam2" type='text/javascript' src='http://192.168.1.20:80/jsv/SncViewer.js'></script><script>cam2.SNC.writeViewer({sz:'4',ptz:'1',fps:'15',iPS:'1'})</script>
</body>
</html>

Thanks in advance

4

2 回答 2

1

I would build a javascript file which will call the scripts using ajax. And load them one by one.

于 2013-10-14T11:10:38.757 回答
1

I'm guilty for using jQuery here, also I've chosen $(window).load over $(document).on('ready') for this - furthermore it's untested!

$(window).load(function() {
    /**
     *  Array of IPs to load
     *  Empty Cameras = {} object 
     *  for Internal name-spacing.
    **/
    var Ips = ["192.168.1.10:80", "192.168.1.20:80"], 
        Suffix = "/jsv/SncViewer.js",
        Cameras = {};

    /** 
     *  For each IP, get script from
     *  IP Array, Keep the saved variable/SNC
     *  within Camera.camX.
    **/
    for( var x = 0; x < Ips.length; x++ ) {
       $.getScript({
           url: "http://"+ Ips[x] + Suffix +"",
           success: function( data ) {
               //May be data.writeViewer..!
               Cameras['cam'+ x +''] = 
                  SNC.writeViewer({sz:'4',ptz:'1',fps:'15',iPS:'1'});
           } 
       });     
    }
});

//Expected Output.
Cameras = {
    cam1 : //SNC Obj,
    cam2 : //SNC Obj
}
于 2013-10-14T11:20:33.500 回答