admin管理员组文章数量:1315287
I am learning web development and trying to achieve task of adding external webpage to a simple HTML page. So, I have a text box where I need to put the URL and based on that the iframe should render.
Webpage renders properly when src
attribute is loaded directly using .attr
property of jquery
.
Working example without the text field:
HTML
<div id="mydiv">
<iframe id="frame" src="" width="100%" height="300">
</iframe>
</div>
<button id="button">Load</button>
SCRIPT
$(document).ready(function(){
$("#button").click(function () {
$("#frame").attr("src", "/");
});
});
Below is what I want
HTML
Enter the URL
<input id="url" type="text"/>
<div id="mydiv">
<iframe id="frame" src="" width="100%" height="300">
</iframe>
</div>
<button id="button">Load</button>
Script
<script>
$(document).ready(function(){
$("#button").click(function () {
var x = $("#url").val();
$("#frame").attr('src', 'x');
});
});
</script>
I referred this SO LINK but could not find the answer. My JSfiddle novice attempt tells an error message as {"error": "Please use POST request"}
. Do I need to use load
jquery method. I just want to read the content of textbox and open the page in iframe with a buttons click. Link to my JSFiddle
I am learning web development and trying to achieve task of adding external webpage to a simple HTML page. So, I have a text box where I need to put the URL and based on that the iframe should render.
Webpage renders properly when src
attribute is loaded directly using .attr
property of jquery
.
Working example without the text field:
HTML
<div id="mydiv">
<iframe id="frame" src="" width="100%" height="300">
</iframe>
</div>
<button id="button">Load</button>
SCRIPT
$(document).ready(function(){
$("#button").click(function () {
$("#frame").attr("src", "https://www.wikipedia/");
});
});
Below is what I want
HTML
Enter the URL
<input id="url" type="text"/>
<div id="mydiv">
<iframe id="frame" src="" width="100%" height="300">
</iframe>
</div>
<button id="button">Load</button>
Script
<script>
$(document).ready(function(){
$("#button").click(function () {
var x = $("#url").val();
$("#frame").attr('src', 'x');
});
});
</script>
I referred this SO LINK but could not find the answer. My JSfiddle novice attempt tells an error message as {"error": "Please use POST request"}
. Do I need to use load
jquery method. I just want to read the content of textbox and open the page in iframe with a buttons click. Link to my JSFiddle
1 Answer
Reset to default 5Can you try this simple example - I've defaulted the input to https://en.wikipedia
but you can try other URLs in there.
$(document).ready(function(){
$("#button").click(function () {
var url = $('#url').val();
$("#frame").attr("src", url);
});
});
<script src="https://ajax.googleapis./ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="mydiv">
<input id="url" type="text" value="https://en.wikipedia"/>
<iframe id="frame" src="" width="100%" height="300">
</iframe>
</div>
<button id="button">Load</button>
本文标签: javascriptHow to embed iFrame with external websiteStack Overflow
版权声明:本文标题:javascript - How to embed iFrame with external website - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741972253a2407910.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论