Add items from a python list to a javascript array

Darryl Doherty darryl.doherty at
Sat Sep 19 09:25:20 CEST 2015

I have a kiosk for digital signage which has a html index file with a javascript which rotates through other html files using iframe at timed intervals. What I want to do is edit the array in the index file with Python to add and remove the HTML file paths from the array. I have a list of all file paths in the python list, so I want to select a path from the list and add it to the javascript array. In addition I want to be able to use python to remove file paths from the array when needed. I'm new to Python so some code examples would be appreciated. Thanks.

File paths:
Python script: '/users/admin/desktop/
HTML file: '/users/admin/desktop/msa0007/content/index.html'
Other html files live in sub directories under '/users/admin/desktop/msa0007/content/'

Python List:
mylist = ['/users/admin/desktop/msa0007/content/test1/test1.html', '/users/admin/desktop/msa0007/content/test2/test2.html', '/users/admin/desktop/msa0007/content/test3/test3.html', '/users/admin/desktop/msa0007/content/test4/test4.html', '/users/admin/desktop/msa0007/content/test5/test5.html', '/users/admin/desktop/msa0007/content/test6/test6.html']

Javascript Array:
var frames = Array('/users/admin/desktop/msa0007/content/test1/test1.html', '/users/admin/desktop/msa0007/content/test2/test2.html', '/users/admin/desktop/msa0007/content/test3/test3.html', '/users/admin/desktop/msa0007/content/test4/test4.html');

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Changing Pages... Please Wait</title>
<script type="text/javascript">
    var frames = Array('/users/admin/desktop/msa0007/content/test1/test1.html', '/users/admin/desktop/msa0007/content/test2/test2.html', '/users/admin/desktop/msa0007/content/test3/test3.html', '/users/admin/desktop/msa0007/content/test4/test4.html');
    var i = 0, len = frames.length;
    function ChangeSrc() {
        document.getElementById('frame').src = frames[i];
        if (i >= len-1) { i = 0 } else { i++; };
        setTimeout('ChangeSrc()', (15 * 1000));
    window.onload = ChangeSrc;
<body style="margin:0px;padding:0px;overflow:hidden">
<iframe src="about:blank" name="frame" id="frame" frameborder="0" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:100%;width:100%;position:absolute;top:0px;left:0px;right:0px;bottom:0px" height="100%" width="100%"></iframe>

More information about the Python-list mailing list