user1468537
user1468537

Reputation: 703

asp.net div/iframe as target

I have a div with called mainContent and if I click a link I want to clear maincontent, add an iframe to the div, and open up the page from the link in the iframe

How to go about doing that? I assume some JS is needeD?

Upvotes: 0

Views: 706

Answers (3)

Magnus
Magnus

Reputation: 46997

<a href="javascript:SetContent();">Some link</a>
<script>
    function SetContent()
    {
       document.getElementById('mainContent').innerHTML = 
          "<iframe width=" + screen.width + "px height=" + screen.height +  
          "px src='http://www.SomeUrl.com'></iframe>";
    }
    </script>

Upvotes: 1

ankur
ankur

Reputation: 4733

Try this snippet. you need to include jquery library for using this.

function appendContent(){
$('#mainContent').html('');
$('#mainContent').html('<iframe name="myiframe" width=620 height=380 src="http://stackoverflow.com" frameborder="1"></iframe>');
}

Upvotes: 0

Alvin Wong
Alvin Wong

Reputation: 12440

Like this?

<script type="text/javascript">
function addiframe(){
    document.getElementById("maincontent").innerHTML='<iframe name="myiframe"></iframe>';
}​
</script>
<div id="maincontent">asd</div>
<a href="//example.com" onclick="addiframe()" target="myiframe">click</a>​

Upvotes: 0

Related Questions