onclick javascript重定向到另一个页面

时间:2013-01-22 01:40:23

标签: javascript jquery

单击立方体图像后如何将立方体图像重定向到另一个链接 现在在js它重定向到google.com但它在另一个窗口打开 但我希望它显示在同一窗口中

<div class="row">
                <div class="span10">
                    <div class="melonhtml5_gallery">
                        **<div onclick="window.open('http://www.google.com', '_blank');" data-caption="Fans" data-image="http://www.defie.co/designerImages/thumbnails/inventory.png"></div>**
                        <div data-caption="Paul Scholes" data-image="http://www.defie.co/designerImages/thumbnails/search.png"></div>
                        <div data-caption="Wayne Rooney" data-image="http://www.defie.co/designerImages/thumbnails/yourFile.png"></div>
                        <div data-caption="Sir Alex Ferguson" data-image="http://www.defie.co/designerImages/thumbnails/shareFiles.png"></div>
                        <div data-caption="Champ" data-image="http://www.defie.co/designerImages/thumbnails/custFile.png"></div>
                        <div data-caption="Group" data-image="http://www.defie.co/designerImages/thumbnails/custQuote.png"></div>
                        <div data-caption="Ryan Giggs" data-image="http://www.defie.co/designerImages/thumbnails/saleOrders.png"></div>
                        <div data-caption="David Beckham" data-image="http://www.defie.co/designerImages/thumbnails/custInvoice.png"></div>
                        <div data-caption="Champ" data-image="http://www.defie.co/designerImages/thumbnails/vendorProfile.png"></div>
                        <div data-caption="Group" data-image="http://www.defie.co/designerImages/thumbnails/vendorQuote.png"></div>
                        <div data-caption="Ryan Giggs" data-image="http://www.defie.co/designerImages/thumbnails/buyOrders.png"></div>
                        <div data-caption="David Beckham" data-image="http://www.defie.co/designerImages/thumbnails/vendorInvoice.png"></div>
                        <div data-caption="Champ" data-image="http://www.defie.co/designerImages/thumbnails/accountsReceivable.png"></div>
                        <div data-caption="Group" data-image="http://www.defie.co/designerImages/thumbnails/customerRMA.png"></div>
                        <div data-caption="Ryan Giggs" data-image="http://www.defie.co/designerImages/thumbnails/production.png"></div>
                        <div data-caption="David Beckham" data-image="http://www.defie.co/designerImages/thumbnails/CRM.png"></div>
                    </div>
                </div>

1 个答案:

答案 0 :(得分:3)

_blank更改为_self。这将使目标从新窗口变为当前窗口

jQuery的:

一般情况下,我避免将事件附加到div,并使用链接或按钮来使用点击事件,但无论如何......

$('.melonhtml5_gallery').find('div').click(function(){
  window.open($(this).attr('data-image'), '_self')
  //you can refer to attributes using the following:
  //$(this).attr('data-caption')
})