HTML variable for URL -
i have web page 6 streaming ip cams. part of code below:
<a target="_blank" href="http://172.28.###.##:102"><img src="http://172.28.###.##:102/videostream.cgi?user=username&pwd=password" width="400" height="300">
when ip changes, need edit above ip times 6. i've searched kind of variable use make 1 change 6 cams.
below not work included show i'm trying do.
<head> <script type="text/javascript"> var server = "172.28.###.##"; var url = "http://" + server + ":102/videostream.cgi?user=username&pwd=password"; </script> </head> <body> <a href = "<script>" url "</script>" </body> </html>
can done? or other way?
you're on right track, you're mixing javascript html. doesn't interpret way think would:
<a href = "<script>" url "</script>"
consider html , javascript 2 separate things. build html markup, use javascript code target , modify elements within markup. example, might have html elements this:
<a id="camlink1" target="_blank" href="http://172.28.###.##:102"> <img id="camimage1" src="http://172.28.###.##:102/videostream.cgi?user=username&pwd=password" width="400" height="300">
notice id
values. long values unique within entire page, can target values , update attributes on html elements. this:
document.getelementbyid("camlink1").href = "http://172.28.12.34:102"; document.getelementbyid("camimage1").src = "http://172.28.12.34:102/videostream.cgi?user=username&pwd=password";
putting together, can construct rudimentary script have different id
s links/images , use single variable set them:
<script type="text/javascript"> var server = "172.28.###.##"; var url = "http://" + server + ":102/videostream.cgi?user=username&pwd=password"; document.getelementbyid("camimage1").src = url; // , on, different elements </script>
one additional thing note here html , javascript evaluated in order in it's loaded on page, you'll want javascript code after html elements targets, otherwise getelementbyid()
won't find elements you're looking for. put javascript script
block @ bottom of page.
as develop code, you'll find can reduce duplication , perhaps define patterns allow more maintain without copy/paste code.
Comments
Post a Comment