我希望能夠打開一個新窗口/選項卡後,把重點放在原來的頁面,以同樣的方式,因爲它是這個網站上完成:http://www.vouchercodes.co.uk/laredoute.co.uk如何在打開新窗口後關注主頁面?
1
A
回答
0
它,當你點擊綠色按鈕「獲取代碼和開放的網站」 。
代碼全部在這裏供您查看。我使用了螢火蟲查找將點擊事件綁定到代碼的<a>
對象,該代碼在主瀏覽器窗口後面彈出。我向下滾動查看global.js文件,發現這個:
基本上.blur()
在指定的彈出窗口將通過焦點返回到支持它的瀏覽器的主窗口和return false;
將確保鏈接不會打開在當前窗口中是默認行爲。向下滾動下面的代碼,你會看到底部。
// -- VoucherClick --
// This baby does the funky stuff when the user clicks to reveal the voucher code
(function($) {
$.fn.extend({
voucherClick: function(config) {
return this.each(function() {
// What is the objects parent?
var theObject = $(this);
if ($(this).hasClass('the-image')) {
var theParent = theObject.parent().parent();
} else {
var theParent = theObject.parent().parent().parent();
}
theObject.click(function() {
// Revealed codes have a light yellow background
// First we remove the background of any currently selected vouchers
$('.selected-voucher').css('backgroundColor','#fff').removeClass('selected-voucher');
// Now we add the yellow background. We have to check what was clicked as it affects
// how far up the DOM tree the voucher DIV starts
// We also must check if we are on an indiviual page with an expired voucher,
// because the yellow background can overlap the left hand edge of the voucher
if (theParent.parent().hasClass('individual-expired')) {
} else {
theParent.css('backgroundColor','#ffffee').addClass('selected-voucher');
}
// Check to see if the voucher has alread been revealed - we only want to run this
// if it hasn't yet been clicked
if (!theParent.data('voucherRevealed')) {
// Make a note that this voucher has been clicked
theParent.data('voucherRevealed', true)
// Make a note of the voucher code and create the revealed code module
var thisCode = theParent.find('strong').html();
// If the code is over 18 characters, we need to reduce the font size
if (thisCode.length > 8) {
thisCode = '<span class="revealedVoucherCode small">' + thisCode + '</span>';
} else {
thisCode = '<span class="revealedVoucherCode">' + thisCode + '</span>';
}
// Fade out the initial module and fade in the revealed voucher module
theParent.find('.code-wrapper').fadeOut('normal', function() {
// If it's an individual page there is no H3
if (theParent.find('h3').length == 0){
// So we add the revealed module after the dates
theParent.find('.dates').after('<div class="revealedVoucher">' + thisCode + '</div>');
} else {
theParent.find('h3').after('<div class="revealedVoucher">' + thisCode + '</div>');
}
theParent.find('.revealedVoucher').fadeIn();
})
}
// Open the merchant link in a new window
var mer_window = window.open(theObject.attr('href'), '_blank', 'toolbar=1,location=1,directories=1,scrollbars=1,resizable=1,status=1,menubar=1');
// Where browsers support it, let's pop this new window BEHIND the current window
if (typeof mer_window === "object") {
mer_window.blur();
}
// Reveal the What Just Happened Text, which was set up in the VoucherInit function
theParent.find('.what-just-happened').slideDown();
// Don't open the link in this current window
return false;
}); // end theObject click function
}) // end this.each function
} // end function(config)
}) // end $.fn.extend
}) (jQuery);
0
根據上面的例子中,我已經把下面的代碼,但點擊時無法正常工作......
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript">
(function($) {
$.fn.extend({
myClick: function(config) {
return this.each(function() {
var theObject = $(this);
theObject.click(function() {
var new_window = window.open(theObject.attr('href'), '_blank', 'toolbar=1,location=1,directories=1,scrollbars=1,resizable=1,status=1,menubar=1');
if (typeof new_window === "object") {
new_window.blur();
}
return false;
});
})
}
})
}) (jQuery);
$('.fade').myClick();
</script>
</head>
<body>
<a href="http://www.google.com" class="fade" target="_blank">Google</a><br />
</body>
</html>
相關問題
- 1. 關閉從主頁面打開的新窗口後,頁面正在刷新
- 2. 如何在<form>打開新窗口後刷新主頁?
- 3. 在新窗口中打開頁面
- 4. 在新窗口中打開asp.net頁面
- 5. HTML:在新窗口中打開頁面
- 6. 打開新窗口,不關注它
- 7. 刷新頁面並打開新窗口
- 8. 如何在新標籤頁/窗口中打開ASP頁面?
- 9. 打開一個新窗口並在5秒後關閉窗口
- 10. 如何在頁面關閉時打開調查窗口?
- 11. Telerik窗口在每次頁面刷新後自動打開
- 12. Javascript頁面在打開新窗口後停止響應
- 13. 打開新窗口後強制按鈕重新加載頁面
- 14. 如何在javafx的相同窗口中打開新頁面
- 15. 如何防止在新窗口中打開iframed頁面
- 16. 如何在同一頁面打開一個新窗口
- 17. 如何使用javascript在新窗口中打開頁面
- 18. 如何在新窗口中打開頁面併發送數據?
- 19. 如何在新窗口中打開PHP /表單結果頁面?
- 20. 如何在新窗口中打開當前頁面
- 21. 如何創建關閉主窗口時打開的窗口?
- 22. 如何打開彈出窗口並刷新彈出窗口關閉時打開的頁面?
- 23. 如何在y關閉第一個窗口後打開一個新窗口?
- 24. 彈出窗口在我關閉並刷新頁面後繼續打開?
- 25. 如何從Qt的主窗口打開一個新窗口?
- 26. 如何在jQUERY關閉彈出窗口後刷新父頁面?
- 27. 如何打開新窗口
- 28. 關閉模式窗口後刷新主頁面
- 29. 在主窗口中打開新的UserControl
- 30. 無需在新窗口中打開頁面或使用JavaScript在新窗口中打開網頁html元素值
你可能會有點不僅僅是更具體的「像這樣現場」。我們應該怎樣做才能重現您之後的效果? – Patrick 2010-10-03 11:20:45
當您點擊一個名爲「Get Code&Open Site」的大綠色按鈕時,Web瀏覽器會在後臺打開一個新窗口 - 這就是我所追求的,簡而言之。 – Ian 2010-10-03 11:27:04