我有一个关于更改iframe ID的问题。我希望在启动某个功能时更改id。
所以当
<a class="btn-blue" ng-click="initiatePurchase()">Upgrade Now</a>
单击,initPurchase()函数启动
这是功能:
subscriptionControllers.controller('subscriptionController',['$scope','$http','$window','$location','restManager',
function($scope,$http,$window,$location,restManager){
$scope.initiatePurchase = function(){
console.log('initiating purchase');
var data = {
redirectUrl: restManager.redirectOnFinishUrl
};
restManager.purchaseCurrentPlan.post(data,
function(success){
if(success == undefined) throw "ERROR: Did not return a valid redirect url";
console.log('successfully initiated purchase- redirecting to ',success.redirect);
//we can not use location.path here - as we are moving away from our domain
//$window.location.href = success.redirect;
document.getElementById('hpwsFrame').src = success.redirect;
},
function(error){
console.log('error initiating purchase');
}
);
}
}
]);
所以我希望改变目标iframe的ID:
<iframe class="iframe" id="hpwsFrame" allowfullscreen="" frameborder="0">
</iframe>
有关如何执行此操作的任何提示,是否会添加到启动购买功能?
谢谢
编辑**
我提出有关ID的问题的原因是因为如果我的iframe设置如此:
<iframe class="iframe" sc="blahblah.html" id="hpwsFrame" allowfullscreen="" frameborder="0"></iframe>
当函数启动时,src不会被更改,它只是按原样保持不变。
subscriptionControllers.controller('subscriptionController',['$scope','$http','$window','$location','restManager',
function($scope,$http,$window,$location,restManager){
$scope.initiatePurchase = function(){
console.log('initiating purchase');
var data = {
redirectUrl: restManager.redirectOnFinishUrl
};
restManager.purchaseCurrentPlan.post(data,
function(success){
if(success == undefined) throw "ERROR: Did not return a valid redirect url";
console.log('successfully initiated purchase- redirecting to ',success.redirect);
//THIS DOES NOTHING
document.getElementById('hpwsFrame').src = success.redirect;
},
function(error){
console.log('error initiating purchase');
}
);
}
}
]);
我仍然想知道一旦initPurchase函数启动后如何更改id,如果有人可以帮助我,我会非常感激。
谢谢