Iframe URL变量使用HTML页面中的当前日期进行更新

时间:2015-10-03 07:22:56

标签: javascript jquery html iframe

我有一个网页查询,其中包含多个iframe内容。在那个iframe URL上有一个可变的日期,我需要自动更新当前日期。你能告诉我怎么做,我不是用PHP。 代码如下:

<html>
<head> </head>
<body>
1. frame 
<iframe src="http://example.com/gui/v3/admin/oss/date'2015-06-15'/" border="0" style="width:100%; height:100%;"></iframe>

2. frame
<iframe src="http://example1.com/gui/v3date'2015-06-15'/admin" border="0" style="width:100%; height:100%;"></iframe>

3. frame
<iframe src="http://example2.com/explorer/index.html#/resources/network.action_set?modified_on%3E%20date('2015-06-09')" border="0" style="width:100%; height:100%;"></iframe>
4. frame
<iframe src="http://example2.com/explorer/index.html#/resources/network.cell_set?modified_on%3E%20date('**2015-06-15**')" border="0" style="width:100%; height:100%;"></iframe>
5. 
<iframe src="http://example3.com/explorer/index.html#/resources/monitor.platform_alerts?form=%7B%date('2015-06-11')" border="0" style="width:100%; height:100%;"></iframe>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

您可以通过Javascript动态创建iframe。 E.g:

var d = new Date(),
    year = d.getFullYear(),
    month = d.getMonth() + 1,
    day = d.getDate(),
    today = year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);

document.body.innerHTML = ('<iframe src="http://example.com/gui/v3/admin/oss/date\'__DATE__\'/" border="0" style="width:100%; height:100%;"></iframe>' +
'<iframe src="http://10.65.152.4:5000/gui/v3/admin/oss/vmumuas3x/" border="0" style="width:100%; height:100%;"></iframe>' +
'<iframe src="http://example2.com/explorer/index.html#/resources/network.action_set?modified_on%3E%20date(\'__DATE__\')" border="0" style="width:100%; height:100%;"></iframe>' +
'<iframe src="http://example2.com/explorer/index.html#/resources/network.cell_set?modified_on%3E%20date(\'**__DATE__**\')" border="0" style="width:100%; height:100%;"></iframe>' +
'<iframe src="http://example3.com/explorer/index.html#/resources/monitor.platform_alerts?form=%7B%date(\'__DATE__\')" border="0" style="width:100%; height:100%;"></iframe>').replace(/__DATE__/g, today);