2 回答
TA贡献1827条经验 获得超4个赞
在 javascript 本身中设置 iFrame URL。
function getPrice() {
var plans = document.getElementsByName('plans');
var paymentFrame = document.getElementById('paymentFrame');
var selectedPlan;
for (index=0; index < plans.length; index++) {
if (plans[index].checked) {
selectedPlan = plans[index].getAttribute('data-price');
break;
}
}
paymentFrame.src="https://www.website.com/create-ideal-payment.php?betaling="+ selectedPlan + ".00"
return selectedPlan;
}
<input type="checkbox" name="plans" data-price="50">
<input type="checkbox" name="plans" data-price="100">
<input type="checkbox" name="plans" data-price="150">
<button OnClick="javascript:alert(getPrice() + '.00');">Bedrag</button>
<iframe id="paymentFrame" width="350" height="150" style="border-left:0px;border-top:0px;border-right:0px;border-bottom:0px;"></iframe>
TA贡献1798条经验 获得超7个赞
在 HTML 主要中
记下 iframe 的 id
<iframe width="350" id = "IframeID" height="150" style="border-left:0px;border-top:0px;border-right:0px;border-bottom:0px;" ></iframe>
主要 HTML 中引用的 JavaScript
function getPrice() {
var plans = document.getElementsByName('plans');
for (index=0; index < plans.length; index++) {
if (plans[index].checked) {
document.getElementById('result').innerText = 50;
return 50;//plans[index].getAttribute('data-price');
break;
}
}
// For testinhg this is the value will be injected in URL of iframe as query string
return 50
}
window.addEventListener('DOMContentLoaded', (event) => {
console.log(getPrice());
document.getElementById('IframeID').src = "somepage.html?seed=" + getPrice() + ".00";
});
IFrame 源 HTML
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>TEST in IFRame</h1>
</body>
<script>
function getParams() {
var params = {},
pairs = document.URL.split('?')
.pop()
.split('&');
for (var i = 0, p; i < pairs.length; i++) {
p = pairs[i].split('=');
params[ p[0] ] = p[1];
}
return params;
}
var parameters = getParams();
for( var i in parameters ){
console.log( i , parameters[i] );
}
</script>
</html>
添加回答
举报