如何使用 jQuery 将外部网站加载到 iframe 中?

jqueryweb developmentfront end technology

要使用 jQuery 将外部 HTML 加载到 iframe 中,请使用 attr() 方法。在该方法中设置 iframe 的源。您可以尝试运行以下代码来了解如何定位外部 HTML:

示例

<!DOCTYPE html><html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script>
$(document).ready(function(){
   $('#iframe').attr('src', 'https://www.qries.com');});</script></head><body>
<iframe id="iframe" name="myIframe" frameborder="5" width="500" height="300"></iframe>
</body></html>


相关文章