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

2020-05-06 07:37发布

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/

2条回答
成全新的幸福
2楼-- · 2020-05-06 08:26

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>

查看更多
可以哭但决不认输i
3楼-- · 2020-05-06 08:37

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>

查看更多
登录 后发表回答