Which is the correct way to load an Iframe using JQuery?
Actually I have a menu with several links and I want to load each link into The Iframe whenever user clicks on it. I am working on an ASP.NET website with my default page having this menu and Iframe both inside it.
I used Target="IframeName" but I dont want this method due to some other problem with it.
So Please tell me how to create a JQuery function to load such an Iframe. I searched for it and I Found several methods but no one seems to be working and I am struck with it , Moreover I am not able to understand which one is right.
Which is the correct way to load an Iframe using JQuery?
Actually I have a menu with several links and I want to load each link into The Iframe whenever user clicks on it. I am working on an ASP.NET website with my default page having this menu and Iframe both inside it.
I used Target="IframeName" but I dont want this method due to some other problem with it.
So Please tell me how to create a JQuery function to load such an Iframe. I searched for it and I Found several methods but no one seems to be working and I am struck with it , Moreover I am not able to understand which one is right.
Share Improve this question edited Dec 17, 2016 at 12:37 Termininja 7,03612 gold badges50 silver badges50 bronze badges asked Apr 19, 2012 at 3:57 nothingInTheNamenothingInTheName 3134 silver badges11 bronze badges 2- What is the "some other problem" with it. The target method is correct and does not require JavaScript to work. Help if you showed the "several methods." – epascarello Commented Apr 19, 2012 at 4:12
- I know target method is correct but it would be really helpful if you could tell me some method to do it by JQuery – nothingInTheName Commented Apr 19, 2012 at 4:14
2 Answers
Reset to default 8The Iframe HTML Code
<iframe id="myIframe" name="myIframe"></iframe>
jQuery
jQuery("#myIframe").attr("src","newPage.html");
JavaScript
document.getElementById("myIframe").src = "newPage.html";
HTML link
<a href="newPage.html" target="myIframe">FOO</a>
Form submission
<form action="newPage.html" target="myIframe">
<input type="submit" name="btnSubmit" value="clicky"/>
</form>
$('#iFrameName').load('somefile.html');
This selects the iframe (you need id="iFrameName" or the like in the iframe tag) and loads a file into it. But, you can just use the target attribute on the a href.. I see you mention there are problems... what is your DOCTYPE of the html? What problems are you having with a basic a href?