Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading an Iframe With JQuery (Correct Method)

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.

like image 552
nothingInTheName Avatar asked Feb 20 '23 18:02

nothingInTheName


1 Answers

The 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>
like image 61
epascarello Avatar answered Mar 02 '23 21:03

epascarello