HighDots Forums  

Re: How to make injected js execute?

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss Re: How to make injected js execute? in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #31  
Old   
Peter Michaux
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 09:16 AM






On Aug 31, 1:51 am, andrea.giammar... (AT) gmail (DOT) com wrote:
Quote:
Ok Randy, You have a credit inside my code update.
I'm curious if he wants credit in your code.


Quote:
Last line, that doesn't require above clear function and it should be
cross-browser enough to forget this problem, could You confirm it?http://www.devpro.it/code/163.html
"cross-browser enough"?

Script insertion is only multi-browser.

eval() and setTimeout() solutions work way back to ancient browsers
and perhaps could be candidates for the label "cross-browser".


Quote:
Sorry for my self-packing obsession, however if someone is interested
about source, just indent (beautyfing) them, it should be quite clear
to read / understand :-)
Code below.

In addition to the brittle dependence on navigator.userAgent, I see at
least two superficial bugs.

Peter


Quote:
(evalScript = function(e) {
var h = evalScript.node,
s = document.createElement("script");
s.type = "text/javascript";
s.text = e;
h.appendChild(s);
h.removeChild(s);
}).node = document.getElementsByTagName("head")[0] ||
document.getElementsByTagName("*")[0];


// self packed, (more) cross browser/platform alternative
// Special thanks to Randy Webb [comp.lang.javascript]
(function() {
var head = document.getElementsByTagName("head")[0] ||
document.getElementsByTagName("*")[0];
evalScript = /webkit|khtml|shiira|sunrise/
i.test(navigator.userAgent) ?
function(E) {
var s = document.createElement('script');
s.type = "text/javascript";
s.appendChild(document.createTextNode(E));
head.appendChild(s);
head.removeChild(s);
}
: ! /icab|ie 5\.2/i.test(navigator.userAgent) ?
function(E) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.text = E;
head.appendChild(s);
head.removeChild(s)
}
: function(E) {
var div = document.createElement("div"),
style = div.style;
style.position = "absolute";
style.border = style.height = style.left =
style.top = style.width = "0px";
head.appendChild(div);
evalScript = function(e) {
div.innerHTML =
'<script type"text/javascript">'+
E + '</script>';
divr.emoveChild(div.firstChild)
};
evalScript(E)
}
})();


Reply With Quote
  #32  
Old   
Peter Michaux
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 09:19 AM






On Aug 30, 11:21 pm, andrea.giammar... (AT) gmail (DOT) com wrote:
Quote:
On Aug 31, 4:07 am, Randy Webb <HikksNotAtH... (AT) aol (DOT) com> wrote:

But it does *not* work in 7 mac browsers (and that is only the ones I
know about).

as I've said, I don't have Mac and I don't care,
That is an unexpected attitude for a professional.


Quote:
usually, on browser used by 0.01% of net surfers.
This is definitely way off.


Quote:
However, thank You for your link, it seems that my basic proposal,
that I've never called perfect but I called them *proposal*, need just
a simple try catch or to be wrote differenlty for iCab and others
using TextNode, really simple, isn't it?

Well done, I'll update my code ... so, at this point, totally amount
of 2 hours against 7 years? :P
But where did your two hours get you?


Peter



Reply With Quote
  #33  
Old   
andrea.giammarchi@gmail.com
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 03:56 PM



On Aug 31, 4:16 pm, Peter Michaux <petermich... (AT) gmail (DOT) com> wrote:
Quote:
I'm curious if he wants credit in your code.
Since He spent much more time than me to try to solve this problem, I
add his credits in my code.

If He doesn't want its credits, I'll remove instantly ... He should
just tell me ... I don't need his name in my little, personal,
site ... so I can't see where the problem is and credits was add just
for that "big" browser list and their behaviour


Quote:
"cross-browser enough"?

Script insertion is only multi-browser.
probably my bad english doesn't allow me to explain perfectly my
ideas ... thank You for this point


Quote:
In addition to the brittle dependence on navigator.userAgent, I see at
least two superficial bugs.
I found one, bad replacement (function(e) instead of E) ... now,
please tell me where's the other.

P.S. brittle dependence, rotlf, sounds like Randy "disaster with
text" ... I write code for Web surfers, do You write code for
crackers?


Quote:
as I've said, I don't have Mac and I don't care,

That is an unexpected attitude for a professional.
come on guys, I wrote JSL many times ago ... so please don't teach me
how much could be cross-browser a script.

I'm simply realistic, in real life/job/world, 0.01% of bad browser
choice can't be my problem.

If I'm not wrong, Java 1.6 doesn't compile some code for 1.5 or
1.4 ... isn't right?

So, now look at every famous library over the net and test them with
Randy browser list ... it's quite obvious that a developer can't write
code for people who don't care about Web navigation, standardization
and/or features.

In other case, please ignore try catch and Exceptions in every script,
I use IE4 and I don't need your professional code (lol again, IT
runs!)



Quote:
usually, on browser used by 0.01% of net surfers.

This is definitely way off.
....



Quote:
But where did your two hours get you?
two hours to: write code, do few tests with "every day" browsers,
write post on personal blog, read here (thanks You Peter) ... and
finally, create self-packed cross-browser version.

Can You do better? I hope so

Regards,
Andrea Giammarchi



Reply With Quote
  #34  
Old   
andrea.giammarchi@gmail.com
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 04:01 PM



ooops, just last note about external JavaScript injection .... I wrote
this post many months ago.

What kind of browser doesn't support them?

http://webreflection.blogspot.com/20...ic-import.html


Reply With Quote
  #35  
Old   
Randy Webb
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 04:49 PM



andrea.giammarchi (AT) gmail (DOT) com said the following on 8/31/2007 2:21 AM:
Quote:
On Aug 31, 4:07 am, Randy Webb <HikksNotAtH... (AT) aol (DOT) com> wrote:
How do you debug code that doesn't exist anymore? There are more reasons
to leave it than there are to remove it. It is a choice. I choose to
leave mine.
my debugger works fine and DOM is not persintently incremented



Say again? How is me putting script blocks inside a sole div element
obtrusive for every other script?
just think about document.getElementsByTagName("script") ... and just
think about DOM incrementation
My script code is no more obtrusive than any other script block. Do you
remove the script element that you use to contain your script block
also? And, if you know that the script element is there (because you put
it there) then you know you have to deal with it.

Quote:
The only possible problem that could
*ever* be caused by it is if a div element happened to be duplicated in
which case the script (mine) could be modified to create it's own div
element to use.
there are more problems than one ... but leave your personal DIV there
if You feel lucky.
Use this practice at your own risk if You use third party libraries.
I don't. Most are written by the kind of people that believe that your
script is a solution to the problem at hand.

Quote:
What is foolproof on a PC is to set the .text property of a script
element. Trying to do that on other OS'es is a recipe for disaster.
disaster ... LOL!!!
Yes, as it will fail in half of the browsers out there.

Quote:
But it does *not* work in 7 mac browsers (and that is only the ones I
know about).
as I've said, I don't have Mac and I don't care, usually, on browser
used by 0.01% of net surfers.
I am not going to argue with your useless worthless statistics about a
point that I know to be valid. If you want to continue to believe your
crap percentages, then do so.

Quote:
However, thank You for your link, it seems that my basic proposal,
that I've never called perfect but I called them *proposal*, need just
a simple try catch or to be wrote differenlty for iCab and others
using TextNode, really simple, isn't it?
You mean that garbage, err code, that relies on navigator.userAgent that
sends Safari3 on Windows down the wrong path?

Quote:
Well done, I'll update my code ... so, at this point, totally amount
of 2 hours against 7 years? :P
And I have code that is 99% fail proof, you have code that is 50% fail
proof.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #36  
Old   
Randy Webb
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 04:50 PM



andrea.giammarchi (AT) gmail (DOT) com said the following on 8/31/2007 4:51 AM:
Quote:
Ok Randy, You have a credit inside my code update.
Please remove my name from your code as I don't want to be associated
with it in its present form. It isn't worth using on a controlled
Intranet much less the web.

Quote:
Last line, that doesn't require above clear function and it should be
cross-browser enough to forget this problem, could You confirm it?
http://www.devpro.it/code/163.html
Confirm that it doesn't even come close to satisfying a "cross-browser"
desire? Sure, I can confirm that.

Quote:
Sorry for my self-packing obsession, however if someone is interested
about source, just indent (beautyfing) them, it should be quite clear
to read / understand :-)
It isn't worth reading and trying to learn from though as it is fraught
with Bad Practices and faulty coding.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #37  
Old   
Randy Webb
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 04:51 PM



Peter Michaux said the following on 8/31/2007 10:16 AM:
Quote:
On Aug 31, 1:51 am, andrea.giammar... (AT) gmail (DOT) com wrote:
Ok Randy, You have a credit inside my code update.

I'm curious if he wants credit in your code.
I want nothing to do with it in its present state as it doesn't even
qualify as decent code much less good code.

<snip>

Quote:
In addition to the brittle dependence on navigator.userAgent, I see at
least two superficial bugs.
It has more problems than that

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #38  
Old   
Randy Webb
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 04:54 PM



andrea.giammarchi (AT) gmail (DOT) com said the following on 8/31/2007 4:56 PM:
Quote:
On Aug 31, 4:16 pm, Peter Michaux <petermich... (AT) gmail (DOT) com> wrote:
I'm curious if he wants credit in your code.
Since He spent much more time than me to try to solve this problem, I
add his credits in my code.

If He doesn't want its credits, I'll remove instantly ... He should
just tell me ... I don't need his name in my little, personal,
site ... so I can't see where the problem is and credits was add just
for that "big" browser list and their behaviour
I have already responded to that in two other replies, but please remove
my name from that, ummm, "code".

Quote:
In addition to the brittle dependence on navigator.userAgent, I see at
least two superficial bugs.
I found one, bad replacement (function(e) instead of E) ... now,
please tell me where's the other.

P.S. brittle dependence, rotlf, sounds like Randy "disaster with
text" ... I write code for Web surfers, do You write code for
crackers?
You don't write code for "web surfers", you write code for "web surfers
that use a UA that fits into my little world of browser scripting ability".

Quote:
as I've said, I don't have Mac and I don't care,
That is an unexpected attitude for a professional.
come on guys, I wrote JSL many times ago ... so please don't teach me
how much could be cross-browser a script.
Why? You could learn a lot based on what you have written so far.

Quote:
I'm simply realistic, in real life/job/world, 0.01% of bad browser
choice can't be my problem.
I am curious where you got that 0.01%. Did it come off the top of your
head or out of your posterior as it would be about as reliable from one
place as the other.

<snip>

Quote:
But where did your two hours get you?
two hours to: write code, do few tests with "every day" browsers,
write post on personal blog, read here (thanks You Peter) ... and
finally, create self-packed cross-browser version.

Can You do better? I hope so
I already have, and will continue to make it even better. That can't be
said for your code at the present time because you have already decided
that it is as good as it needs to be (even though it isn't even close).

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #39  
Old   
Randy Webb
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 04:57 PM



andrea.giammarchi (AT) gmail (DOT) com said the following on 8/31/2007 5:01 PM:
Quote:
ooops, just last note about external JavaScript injection .... I wrote
this post many months ago.

What kind of browser doesn't support them?

http://webreflection.blogspot.com/20...ic-import.html

If you want to know if something works or not, you could test it
yourself. Since you don't care about any non-PC browser what does it
matter? Besides, it would be trivial to answer you if you would make all
the code for it easily available rather than having to wade through 4 or
5 pages to find it. No thanks.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #40  
Old   
andrea.giammarchi@gmail.com
 
Posts: n/a

Default Re: How to make injected js execute? - 08-31-2007 , 06:33 PM



On Aug 31, 11:54 pm, Randy Webb <HikksNotAtH... (AT) aol (DOT) com> wrote:
Quote:
I have already responded to that in two other replies, but please remove
my name from that, ummm, "code".
done, however, thank You for that table


Quote:
You don't write code for "web surfers", you write code for "web surfers
that use a UA that fits into my little world of browser scripting ability".
Hey Randy, I do my work as you do your one.
At the same time, I don't think I code better than You ... and I don't
think You code better than me too.

You can write code for Commodore-64 too if You like this way and You
think this is a good way to create big size "revolutionary" scripts
using double time to do them.


Quote:
Why? You could learn a lot based on what you have written so far.
And You could learn a lot on what I written too ;-)


Quote:
I am curious where you got that 0.01%. Did it come off the top of your
head or out of your posterior as it would be about as reliable from one
place as the other.
http://www.w3schools.com/browsers/browsers_stats.asp
http://www.upsdell.com/BrowserNews/stat.htm


Quote:
I already have, and will continue to make it even better. That can't be
said for your code at the present time because you have already decided
that it is as good as it needs to be (even though it isn't even close).
I've decieded anything about my code ... it is a proposal, just
modified, and last modified version works with probably every row
present in your table (but if a browser is buggy, it can't be my
problem)


Quote:
My script code is no more obtrusive than any other script block. Do you
remove the script element that you use to contain your script block
also? And, if you know that the script element is there (because you put
it there) then you know you have to deal with it.
of course ... but don't You never think about other developers that
uses third libraries?
I code like You, everything is "mine" and everything is under my
control ... but if I publish something publicly it should care about
every other library (do You know Open Ajax and similar projects?).

So, do You code only for yourself? I think this is not an error, but
this is not a good practice too, expecially if You public your code
over the net.


Quote:
I don't. Most are written by the kind of people that believe that your
script is a solution to the problem at hand.
because it's a solution for 98% (ok, ok ... 99.9 is too much ...) of
*USED* browsers ... I usually prefere small "quite totally cross
browser" scripts instead of "totally cross browser" big size scripts.

Of course, it's my choice for this crazy Web world, so it's not the
best way to code, just a personal choice.


Quote:
You mean that garbage, err code, that relies on navigator.userAgent that
sends Safari3 on Windows down the wrong path?
Uh? last script (and probably first one too) works with Safari 2 too,
should I care about Safari 1 and 0.1 beta too?
I remember a WebKit 0.1 alpha, should I test them too?


Quote:
And I have code that is 99% fail proof, you have code that is 50% fail
proof.
50% of browsers ... but 98% of surfers


Quote:
If you want to know if something works or not, you could test it
yourself.
That's what I do everytime


Quote:
Since you don't care about any non-PC browser what does it
matter?
This is your opinion, not my way to code (and I've recently bought
a Nintento Wii too to code for dedicated Opera version ... do You test
your code for new browsers too or only for "not-so-used" one?)


Quote:
Besides, it would be trivial to answer you if you would make all
the code for it easily available rather than having to wade through 4 or
5 pages to find it. No thanks.
eh eh ... ok Randy, You are the one!

I didn't know this "place" and probably, if You're one "boss" here,
I'll never come back again.

Good luck with your unique and perfect way to code and find solutions
(really, "only" 7 years for this simple problem? ...)

I went here to talk about my proposal and possible problems but You
talk only about your way to "perfectly" code and your friends agree
with your ego.

So, finally, I respect You because your work is good enough for your
purpose/goals but my work (I write JavaScript from about 10 years) is
good enough for my goals, so We'll probably talk about JS one day but
I'm sure, not "tomorrow" if this is your way to talk about them.

As I said, really sorry (to everyone) for my bad and not so clear
English knowledge and best regards to everyone,
Andrea Giammarchi



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.