Reputation: 1189
I have SAP system where I can integrate HTML page. This HTML page is launched on Button Click
.
Button click changes the value of Iframe source every time. As I understand the basic, I wrote the below code which is working fine on the first click. The HTML page gets loaded.
<!DOCTYPE html>
<html>
<body onLoad="myFunction()">
<iframe id="myFrame" src="http://www.w3schools.com/" height="1000" width="2000" frameborder="0"></iframe>
<script>
function myFunction() {
document.getElementById("myFrame").src = sap.byd.ui.mashup.context.inport.FirstName;
}
</script>
</body>
</html>
When I click second time the value for sap.byd.ui.mashup.context.inport.FirstName
changes, but there is no change in the Iframe.
I saw there is something called onChange
event, but I am not able to write use it correctly. Can anyone help me to do this?
Upvotes: 0
Views: 152
Reputation: 3739
An ugly solution would be to constantly check if the value of the FirstName
, in order to check for changes.
<script>
var _firstname;
function myFunction() {
document.getElementById("myFrame").src = sap.byd.ui.mashup.context.inport.FirstName;
_firstname = sap.byd.ui.mashup.context.inport.FirstName;
}
setInterval(function() {
if (_firstname != sap.byd.ui.mashup.context.inport.FirstName)
myFunction();
}, 1000) //check every second to see if FirstName value changed
</script>
But I would definitely recommend calling myFunction()
from wherever you change sap.byd.ui.mashup.context.inport.FirstName
to avoid the use of setInterval
. If you can change the value of a javascript object, you should be able to make a function call too. I suggest you research how to call a javascript function and just call myFunction()
right after you change FirstName
. Then you will not need the setInterval
.
Upvotes: 1