Есть ли способ создать неспецифическую функцию для отображения iFrame при нажатии?
Мое рассуждение связано с тем, что у меня есть несколько ссылок iFrame на некоторые другие страницы, и вместо того, чтобы требовать, чтобы браузер загружал все страницы в начале, он будет загружать их по запросу.
Именно так я и думал об этом:
HTML
<a class="viewFrame">
<img src="../button.png"/>
</a>
<iFrame class="frame" src="" title="http://linkToiFrame.com"/>
Jquery
$('viewFrame').on("click", function(){
$('frame').attr("src", $('frame').attr("title"));
});
/*Will have a function here to remove the attribute
I am unsure as to whether or not I even need to do this, or if I just
hide the iFrame after, this way I don't have to load it multiple times
if the user clicks the link multiple times.*/
$('close').on("click", function(){
$('frame').attr("src", "");
});
Мне любопытно узнать, действительно ли это похоже на практический способ сделать это, или если есть какие-то лучшие пути.
Любая помощь приветствуется!
frame
является классом iframe, так как он может работать только с $('frame')
вам нужно написать $('.frame')
'.' is used for classes and '#' for id's
"My reasoning is because I have several iFrame's linking to some other pages, and instead of having to require the browser to load all the pages at the start it will load them on request."