How to use javascript variable in iframe src

how to write javascript variable in iframe src?

how

<iframe id="showskill" scrolling="yes" height="350" width ="350" src="http://localhost/POSkill/skillshow.aspx?user_id="+ ReturnURL() ></iframe> 

Here, ReturnURL () is a javascript function that returns a value. But the problem is the iframe source. I do not get the return value of the function. I do not put in the right format or is something missing?

Thanks in advance Johnny

+4
source share
2 answers

You cannot use JavaScript variables or functions directly in your html markup this way. What you can do is first define your iframe and then set its source from JavaScript:

 <iframe id="showskill" scrolling="yes" height="350" width ="350" src=""></iframe> <script> document.getElementById("showskill").src = "http://localhost/POSkill/skillshow.aspx?user_id="+ ReturnURL(); </script> 

There are several other ways to achieve something similar, but I really don't want to go through them when I'm not sure what your context is.

+15
source

You cannot add the variable returned by the function directly, as you are here. Do something as shown below.

 var url=ReturnURL(); var urlPath='http://localhost/POSkill/skillshow.aspx?user_id='+url; document.write('<iframe id="showskill" scrolling="yes" height="350" width ="350" src="'+urlPath+'><\/iframe>'); 
+3
source

Source: https://habr.com/ru/post/1388094/


All Articles