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

有帮助吗?

解决方案

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
}

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top