如何在页面加载时实现jReject

时间:2013-01-09 14:31:48

标签: jquery

我想在加载页面后加载jReject脚本。 在默认的jReject脚本中,它适用于click,我在页面加载时喜欢它。 应该做些什么改变呢? 我应该把它放在哪里      $(function(){$ .reject();});

这是我在标题中的脚本:

$(function() {
    // Handle external links
    $('a[rel="external"]').click(function() {
        var href = $(this).attr('href');

        // Send external link event to Google Analaytics
        try {
            _gaq.push(['_trackEvent','External Links', href.split(/\/+/g)[1], href]);
        } catch (e) {};

        window.open(href,'jr_'+Math.round(Math.random()*11));
        return false;
    });

    // Handle displaying of option links
    $('em.option').css({
        cursor: 'pointer',
        fontSize: '1.1em',
        color: '#333',
        letterSpacing: '1px',
        borderBottom: '1px dashed #BBB'
    }).click(function() {
        var self = $(this);
        var opt = $.trim(self.text());

        $('ol.dp-c:first').children('li').children('span').each(function() {
            var self = $(this);
            var text = self.text();
            var srch = opt+':';

            // If found, highlight and jump window to position on page
            if (text.search(srch) !== -1) {
                self.css('color','red');
                window.location.hash = '#c-'+opt;
                window.scrollTo(0,self[0].offsetTop);
            }
        });
    });

    /* Demo Codes */

    $('#demo3').click(function() {
        $.reject({
            reject: { all: true }, // Reject all renderers for demo
            header: 'Your browser is not supported here', // Header Text
            paragraph1: 'You are currently using an unsupported browser', // Paragraph 1
            paragraph2: 'Please install one of the many optional browsers below to proceed',
            closeMessage: 'Close this window at your own demise!' // Message below close window link
        }); // Customized Text

        return false;
    });

});

3 个答案:

答案 0 :(得分:0)

在OP的链接底部:

运行加载(默认选项):

$(function() { $.reject(); });

答案 1 :(得分:0)

来自文档:

  

Run on load(默认选项):$(function(){$ .reject();});

答案 2 :(得分:0)

转动你的代码

$('#demo3').click(function() {
    $.reject({
        reject: { all: true }, // Reject all renderers for demo
        header: 'Your browser is not supported here', // Header Text
        paragraph1: 'You are currently using an unsupported browser', // Paragraph 1
        paragraph2: 'Please install one of the many optional browsers below to proceed',
        closeMessage: 'Close this window at your own demise!' // Message below close window link
    }); 
    return false;
});

进入

$.reject({
        reject: { all: true }, // Reject all renderers for demo
        header: 'Your browser is not supported here', // Header Text
        paragraph1: 'You are currently using an unsupported browser', // Paragraph 1
        paragraph2: 'Please install one of the many optional browsers below to proceed',
        closeMessage: 'Close this window at your own demise!' // Message below close window link
    });