user2176150
user2176150

Reputation: 303

How to assign Iframe url using javascript?

I can not assign the url for the iframe popup window. I am using the below two format to assign the iframe url.But its not working.Please help me to solve this issue.

var hide_id = document.getElementById("<%= hf_id.ClientID %>").value;
var url = "Device_Map.aspx?val='"+ hide_id +"'";
document.getElementById('divMap').innerHTML = '<iframe runat="server" src="' + url + '" id="mm" width="1000" height="500" frameborder="0" scrolling="0" marginheight="0" marginwidth="0" ></iframe><br />';


document.getElementById('divMap').innerHTML = '<iframe runat="server" src="Device_Map.aspx?val='"+ hide_id +"'" id="mm" width="1000" height="500" frameborder="0" scrolling="0" marginheight="0" marginwidth="0" ></iframe><br />';

Upvotes: 0

Views: 399

Answers (3)

varun
varun

Reputation: 76

Here is the code:

For Assigning url to Iframe through javascript Divshow is Div in which Iframe is called, Call Iframecalling() method on any event

<script type="text/javascript">
        function Iframecalling() {
            var queryvalue = 123;
            var url = "DropdownGrid.aspx?ID="+ queryvalue;  
            document.getElementById("Divshow").innerHTML = '<iframe  src="'+url+'" height="450px" width="400px"></iframe>';
        }

    </script>

Upvotes: 1

Prashant Kankhara
Prashant Kankhara

Reputation: 1588

You have set your empty iframe tag in your body and than try to assign the src to it. i have mention and sample below

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
         var hide_id = document.getElementById("<%= hf_id.ClientID %>").value;
         var url = "Device_Map.aspx?val='"+ hide_id +"'";
         $(".frmPass").attr('src', url);
});
</script>
</head>

<body>
...
...

<iframe id="frm" runat="server" class="frmPass" width="900px" height="500px" scrolling="no"
                frameborder="0" style="border: 0;"></iframe>
...
...
</body>

Upvotes: 0

Robert Levy
Robert Levy

Reputation: 29073

the single quotes you are adding around hide_id make the final concatenated string invalid. you want something like

you want var url = "Device_Map.aspx?val=\""+ hide_id +"\"";

or if the server allows it, var url = "Device_Map.aspx?val="+ hide_id;

Upvotes: 0

Related Questions