如何在网页加载时默认显示网页

如何在网页加载时默认显示网页

问题描述:

我使用jQuery将网页加载到div - 而不是使用iframe。

I'm using jQuery to load pages into a div - instead of using iframes.

代码工作得很好(可随意重复使用!)但是,我遇到一个问题,当有人访问网址时,我无法显示网页。

The code works great (feel free to reuse!) However, I have an issue where I cannot display a page when someone visits the URL.

因此,在网页加载时,画布是空的(在菜单旁边),直到访问者点击链接。

So on page load, the canvas is empty (next to the menu) until the visitor clicks a link.

这里是代码

<script>

  $('[data-target]').click( function (e) {
    $.get($(this).attr('href'), function(data){ 
     $('#halloffame').empty(); 
      $(data).find(".partner_body").appendTo("#halloffame");

    });
    e.preventDefault(); // prevent anchor from changing window.location
  }); 
</script>

每当页面被访问时,我想显示的是page-a.html - 看起来这么空。

What I want to show is page-a.html whenever the page is visited - so the page doesn't look so empty.

有没有任何想法?

非常感谢高级:)

Dan

所以我设法使用@ Roberto的建议和我的原始代码

So I managed to resolve this by using @Roberto's suggestion and my original code (Simply added load onto the end)

这是完成的代码,它在网页加载时加载网址(仍允许您在div中打开链接)

Here is the finished code, which loads a URL on page load (and still allows you to open links in a div)

  $('[data-target]').click( function (e) {
    $.get($(this).attr('href'), function(data){ 
     $('#halloffame').empty(); 
      $(data).find(".partner_body").appendTo("#halloffame");

    });
    e.preventDefault(); // prevent anchor from changing window.location
  }); 
  $.get( "pages/accounting-software/", function( data ) { 
       $('#halloffame').empty(); 
        $(data).find(".partner_body").appendTo("#halloffame");

   }); 

希望这有助于任何人尝试实现相同的结果。

Hope this helps anyone else trying to achieve the same result.