使用javascript更改iframe宽度和高度

时间:2017-02-23 12:36:16

标签: javascript jquery iframe

我如何改变iframe的宽度和高度是src链接?使用下面的javascript代码,我可以更改iframe的宽度和高度,但是当有像这样的iframe时

<iframe id="myFrame" src="http://domain.com/page.php?width=400&height=400" height="400" width="400"></iframe>

<button onclick="myFunction()">Change</button>

如何更改宽度和高度page.php?width=400&height=400?可以使用javascript吗?

这是我的javascript代码,用于更改iframe的宽度和高度

<script>
function myFunction() {
    document.getElementById("myFrame").height = "400";
    document.getElementById("myFrame").width = "400";
}
</script>

1 个答案:

答案 0 :(得分:2)

你可以这样做:

import socket
import requests
import json
from Chris import token #for access the token
HOST,PORT='',8888
listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST,PORT))
listen_socket.listen(1)

print("Listenning on port %s" % PORT)

while True:
    client_connection, client_address = listen_socket.accept()
    request = client_connection.recv(1024)
    print(request)

r=requests.get('https://api.netatmo.com/api/getpublicdata?access_token='+token+'&lat_ne=**['+lat_ne+']&lon_ne=['+lon_ne+']&lat_sw=['+lat_sw+']&lon_sw=['+lon_sw+']&filter=TRUE') 
#lat_ne=str(lat+0.2), lon_ne=str(lon+0.2), lat_sw=str(lat-0.2), lon_sw=str(lon-0.2)

json_object = r.json() #json_object = dict

data1=json_object['body'][0]['measures'] 

data2 = sorted(data1.items())[0][1]['res']
#print(sorted(data1.items())[1])
#data3 = sorted(data1.items())[1][1]['res']
data2str = str(data2.values())
#data3str = str(data3.values())
datatemperature = data2str[14:18]
datahumidity = data2str[19:22]



http_response = " The temperature is " + datatemperature  + ". The humidity is " + datahumidity

client_connection.sendall(bytes(http_response.encode('utf-8')))
client_connection.close()

或者你想使用id然后像这样:

function myFunction() {
    $("iframe").width(678);
    $("iframe").height(526);
}

如果您有2个iframe而您只想申请1,那么就像这样:

function myFunction() {
    $("#myFrame").width(678);
    $("#myFrame").height(526);
}

**编辑:**您可以使用<script type="text/javascript"> function myFunction() { $("iframe:eq(1)").width(678); $("iframe:eq(1)").height(526); } </script>

更新iframe的src
.attr