javascript - Preview an html page without opening it - Stack Overflow

On click a image how can another page bepreviewed in the same page without opening the actual page. L

On click a image how can another page be previewed in the same page without opening the actual page. Lets say the url /home/home.php?id=3
The preview should be in the preview div:

 <img src="/home/app/img/toggle.gif" onlclick="show();" />
 <div id="preview"></div>   

On click a image how can another page be previewed in the same page without opening the actual page. Lets say the url /home/home.php?id=3
The preview should be in the preview div:

 <img src="/home/app/img/toggle.gif" onlclick="show();" />
 <div id="preview"></div>   
Share Improve this question edited Jun 11, 2022 at 17:46 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 5, 2010 at 15:54 HulkHulk 34.2k65 gold badges150 silver badges217 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You can use .load() for this. Here's an example, HTML like this:

<img src="/home/app/img/toggle.gif" id="previewBtn" />
<div id="preview"></div>

jQuery like this:

$("#previewBtn").click(function() {
  $("#preview").load("/home/home.php?id=3");
});

Or, if you had lots of previews, something like this more generic works:

<a class="previewBtn" href="/home/home?id=1">Preview 1</a>
<a class="previewBtn" href="/home/home?id=2">Preview 2</a>
<div id="preview"></div>

With this jQuery:

$(".previewBtn").click(function() {
  $("#preview").load(this.href);
});
$(function() {

        $.ajax({
            url: '2.htm',
            success: function(data) {
                $('.result').html(data);
            }
        });
    });

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745343432a4623434.html

相关推荐

  • javascript - Preview an html page without opening it - Stack Overflow

    On click a image how can another page bepreviewed in the same page without opening the actual page. L

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信