I am trying to execute the following code:
<button onclick="increment()">Increment</button>
<div id="iframe">
<script>
var id = 139000;
var link='<iframe src="https://somewebsite.com/something.aspx?sa=1&pid=' id '" height="600px" width="100%" />';
function increment(){
id ;
document.getElementById('iframe').innerHTML = id link ;
}
</script>
</div>
But while executing, the &
in src=""
converts to &
which breaks the original URL and doesn't go to the desired destination. I looked up on the internet but as I am a noob, I was not able to figure it out. Please help me to make this work!
CodePudding user response:
All you need to do is
<button onclick="increment()">Increment</button>
<div id="iframe">
<script>
var id = 139000;
var link='<iframe src="https://somewebsite.com/something.aspx?sa=1&pid=' id
'" height="600px" width="100%" />';
var new_link = link.replaceAll('&','&');
function increment(){
id ;
document.getElementById('iframe').innerHTML = id new_link;
}
</script>
CodePudding user response:
This is definitely a blogger issue, and the reason behind happening is :
The character "&" is an ISO HTML reserved character used to denote the start of a parameter.
To overcome this the Blogger editor translate the &
you enter to the HTML entity, &
, that will display &
when the page or URL is rendered in a browser, so that you don't have to do it yourself.