I want to load an iframe on click, this is what I have so far:
我想在点击时加载一个iframe,这是我目前所拥有的:
$("#frame").click(function () {
$('this').load("http://www.google.com/");
});
It doesn't work. This is the complete code: JS Bin
它不工作。这是完整的代码:JS Bin
5 个解决方案
#1
85
$("#button").click(function () {
$("#frame").attr("src", "http://www.example.com/");
});
HTML:
HTML:
<div id="mydiv">
<iframe id="frame" src="" width="100%" height="300">
</iframe>
</div>
<button id="button">Load</button>
#2
9
$("#frame").click(function () {
this.src="http://www.google.com/";
});
Sometimes plain JavaScript is even cooler and faster than jQuery ;-)
有时简单的JavaScript甚至比jQuery更酷更快;
#3
7
Try $(this).load("/file_name.html");
. This method targets a local file.
试(美元).load(" / file_name.html ");。该方法针对本地文件。
You can also target remote files (on another domain) take a look at: http://en.wikipedia.org/wiki/Same_origin_policy
您还可以针对远程文件(在另一个域中)进行查看:http://en.wikipedia.org/wiki/Same_origin_policy
#4
0
Just in case anyone still stumbles upon this old question:
以防有人还会碰到这个老问题:
The code was theoretically almost correct in a sense, the problem was the use of $('this') instead of $(this), therefore telling jQuery to look for a tag.
从某种意义上说,这段代码在理论上几乎是正确的,问题是使用$('this')而不是$(this),因此让jQuery查找标记。
$(document).ready(function(){
$("#frame").click(function () {
$(this).load("http://www.google.com/");
});
});
The script itself woudln't work as it is right now though because the load() function itself is an AJAX function, and google does not seem to specifically allow the use of loading this page with AJAX, but this method should be easy to use in order to load pages from your own domain by using relative paths.
脚本本身woudln行不通,因为它是现在虽然因为load()函数本身是一个AJAX函数,和谷歌似乎并没有明确允许使用加载这个页面使用AJAX,但是这种方法应该易于使用,以加载页面从您自己的域使用相对路径。
#5
0
here is Iframe in view:
这里是Iframe视图:
<iframe class="img-responsive" id="ifmReport" width="1090" height="1200" >
</iframe>
Load it in script:
加载脚本:
$('#ifmReport').attr('src', '/ReportViewer/ReportViewer.aspx');
#1
85
$("#button").click(function () {
$("#frame").attr("src", "http://www.example.com/");
});
HTML:
HTML:
<div id="mydiv">
<iframe id="frame" src="" width="100%" height="300">
</iframe>
</div>
<button id="button">Load</button>
#2
9
$("#frame").click(function () {
this.src="http://www.google.com/";
});
Sometimes plain JavaScript is even cooler and faster than jQuery ;-)
有时简单的JavaScript甚至比jQuery更酷更快;
#3
7
Try $(this).load("/file_name.html");
. This method targets a local file.
试(美元).load(" / file_name.html ");。该方法针对本地文件。
You can also target remote files (on another domain) take a look at: http://en.wikipedia.org/wiki/Same_origin_policy
您还可以针对远程文件(在另一个域中)进行查看:http://en.wikipedia.org/wiki/Same_origin_policy
#4
0
Just in case anyone still stumbles upon this old question:
以防有人还会碰到这个老问题:
The code was theoretically almost correct in a sense, the problem was the use of $('this') instead of $(this), therefore telling jQuery to look for a tag.
从某种意义上说,这段代码在理论上几乎是正确的,问题是使用$('this')而不是$(this),因此让jQuery查找标记。
$(document).ready(function(){
$("#frame").click(function () {
$(this).load("http://www.google.com/");
});
});
The script itself woudln't work as it is right now though because the load() function itself is an AJAX function, and google does not seem to specifically allow the use of loading this page with AJAX, but this method should be easy to use in order to load pages from your own domain by using relative paths.
脚本本身woudln行不通,因为它是现在虽然因为load()函数本身是一个AJAX函数,和谷歌似乎并没有明确允许使用加载这个页面使用AJAX,但是这种方法应该易于使用,以加载页面从您自己的域使用相对路径。
#5
0
here is Iframe in view:
这里是Iframe视图:
<iframe class="img-responsive" id="ifmReport" width="1090" height="1200" >
</iframe>
Load it in script:
加载脚本:
$('#ifmReport').attr('src', '/ReportViewer/ReportViewer.aspx');