Is it possible to use JQuery to load a url into an

2020-05-06 07:33发布

问题:

Is is possible using JQuery to load the src of an <a> tag into an iframe on the same page as the linked clicked if you can not edit the html?

Something similar to this but instead of getting the value from the input the src value would be the src of the link the person clicks on?

http://jsfiddle.net/kbwood/DLprk/

回答1:

Is this what you want?

$('#url').click(function(e) {
    e.preventDefault();
    $('#display').attr('src', $('#url').attr('href'));
});
iframe { width: 100%; height: 50%; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe id="display"></iframe>
<br>
    <a type="text" id="url" href="http://jquery.com">test</a>



回答2:

That's what target attribute is for.

iframe { width: 100%; height: 50%; }
<iframe id="display" name="display"></iframe>
<br>
    <a href="http://jquery.com" target="display">Load</a>