首先,我很抱歉我的代碼太糟糕了。總新手在這裏。如何根據複選框輸入更改iframe屬性?
爲了好玩,我正在組建一個基本網站,讓您查看sandboxed iframe中的另一個網站。到目前爲止,我從互聯網上找到的代碼和我自己非常基本的html知識中匆匆地把它們混爲一談。我堅持的是如何實現沙箱功能。
我在找的是我在網站上打開和關閉沙箱覆蓋的複選框。我不知道足夠的Java腳本來做到這一點。任何幫助,將不勝感激。
<html>
<head>
<title>
Bubble Wrap
</title>
<script type="text/javascript">
function wrapWebsiteInBubble(){
var browserFrame = document.getElementById("bubble");
browserFrame.src= document.getElementById("wrap").value;
}
</script>
</head>
<body style="font-family:sans-serif;">
<input type="checkbox" id="allow-forms" value="allow-forms"> Allow forms
<input type="checkbox" id="allow-pointer-lock" value="allow-pointer-lock"> Allow pointer lock
<input type="checkbox" id="allow-popups" value="allow-popups"> Allow popups
<input type="checkbox" id="allow-same-origin" value="allow-same-origin"> Allow same origin
<input type="checkbox" id="allow-scripts" value="allow-scripts"> Allow scripts
<input type="checkbox" id="allow-top-navigaton" value="allow-top-navigation"> Allow top navigation
<br>
<form method="post" target="bubble">
<input type="text" id="wrap" style="width:88%;" placeholder="https://www.example.com" name="url"/>
<input style="width:8%;" type="button" value="Wrap" onclick="wrapWebsiteInBubble(); return false;"/>
</form>
<iframe id="bubble" name="bubble" src="http://google.com" style="height:100%; width:100%"></iframe>
</body>
</html>
附: 有什麼我應該做的,以使我的代碼更好?
_P.S。有什麼我應該做的,以使我的代碼更好?_請參閱我更新的答案,並解釋我所做的更改以及原因。 – JustCarty