MyTetra Share
Делитесь знаниями!
Usercsripts для Internet Explorer IE7 PRO и подключение jQuery
Время создания: 17.07.2012 09:16
Текстовые метки: ie7pro, iepro
Раздел: Компьютер - Программирование - Java Script - Greasymonkey
Запись: xintrea/mytetra_syncro/master/base/134250218678aqxzw4i5/text.html на raw.github.com

jQuery для IE7Pro userscripts - почти что Greasemonkey

Есть небольшая проблема в IE7, которая состоит в том, что просто так невозможно использовать в юзер-скриптах библиотеку jQuery. В IE, как обычно, очень странные требования к безопасности, которые не безопасность повышают, а просто мешают пользователям. Секрет в том, что код jQuery надо предварительно подготовить для IE, добавив специальный заголовок. А так же, код библиотеки надо разместить в специальном каталоге, иначе она не будет подключаться.

Ниже дана последовательность действий по решению данной проблемы (английский):

Difficulty

Some weeks ago I made a blog post, about IE7Pro userscripts, the Greasemonkey-like plugin for Internet Explorer 7. I’m still deeply in love with userscripts for both IE7Pro and Greasemonkey, but what a waste of time for spending hours on writing big userscripts with DOM javascripting to extend that “untouchable” website/webapplication.

This should be different! Why not use jQuery for IE7Pro userscripts.

The idea is to load first the jQuery script and then the userscript. Unfortunately a javascript include script like this will not work:

//load jQuery

inc("jquery.js");

/* jsHandler.js */

function inc(filename)

{

var body = document.getElementsByTagName('body').item(0);

script = document.createElement('script');

script.src = filename;

script.type = 'text/javascript';

body.appendChild(script)

}

However, it’s still very easy to let jQuery run for userscripts. First download the latest jQuery lib.

Incase of IE7Pro:

Rename the downloaded jQuery script to: jquery.ieuser.js and place it

in the userscript folder. (path\IEPro\userscripts).

Open the jquery.ieuser.js file and add the following comment block on the top of javascript lib file:

// ==UserScript==

// @name jQuery

// @namespace jQuery

// @include *

// ==/UserScript==

Now you can reload the jQuery file from the preferences – userscript screen in IE7Pro, and enable jQuery. To test it, create a new userscript with the following jQuery code. As soon as it runs, you know that you can use jQuery for every page.

// ==UserScript==

// @name Test

// @namespace Test

// @include *

// @author Lee Boonstra

// ==/UserScript==

$(document).ready(function(){

alert("jQuery in userscripts do work!");

});

 
MyTetra Share v.0.59
Яндекс индекс цитирования