I would like to download the Script of MyBlogLog in AJAX and then put
it in the page.
Does anybody already did that ?
The problems seems to be generic:
1. I call a script Event.observe(window, 'load', ...
2.1 I generate <script></script> under a given Id
2.1.1 with InnerHTML it do not work
2.1.2 with dom elments it works but override the full page
2.2 Using Ajax.Updater it seems connection fails
- What is the best practice tounderstand why the connection is refused ?
- What is the best pratice to include a <script> tag in a given place
of the DOM ? should be usefull for all the gadgets doing stuff like
MyBLogLog, Viadeo, ...
Best Regards,
Jp
--
Jean-Philippe Encausse - Veille / R&D Jalios SA
Jp [at] encausse.net - http://www.encausse.com - http://www.jalias.com
GTalk: jp.encausse [at] gmail.com - SMS: sms [at] jp.encausse.net
Mob: +33 6 82 12 56 99 - Job: +33 1 39 23 92 83 - Tel: +33 1 39 18 90 15
Do it Once, Use it Twice ~ Do it Twice, Make It Once
1. I call a script Event.observe(window, 'load', ...
2.1 I generate <script></script> under a given Id
2.1.1 with InnerHTML it do not work
2.1.2 with dom elments it works but override the full page
2.2 Using Ajax.Updater it seems connection fails
- What is the best practice tounderstand why the connection is refused ?
- What is the best pratice to include a <script> tag in a given place
of the DOM ?
> dynamically creating a <script> tag and inserting
> it into the dom to create functionality once the page has been loaded on
> the client system?
Yes exactly, I'm try to include the script of MyBlogLog that should be:
<script src="http://pub.mybloglog.com/comm2.php?mblID=2006121510341039"
type="text/javascript"></script>
The url is longer normally and it works.
When requesting from browser:
http://pub.mybloglog.com/comm2.php?mblID=2006121510341039
This will return a script that generate <table>
So I try:
Event.observe(window, 'load', function() {
// Using 'static' object
JCMS.plugin.mybloglog.MyBlogLog.insertScript();
});
Then I'm using a <a href="mybloglog url"></a> to retrieve the location
and url to call
JCMS.plugin.mybloglog.MyBlogLog = {
insertScript : function () {
var elm = $('MyBlogLog');
var url = elm.href;
var address = url.substring(0,url.indexOf('?'));
var params = $H(url.toQueryParams());
/* Option 1
var script = document.createElement('SCRIPT');
script.type='text/javascript';
script.src = address+"?"+params.toQueryString();
elm.parentNode.appendChild(script);
*/
/* Option 2
// elm.parentNode.innerHTML = "<script type='text/javascript'
src='"+address+"?"+params.toQueryString()+"'></script>"
*/
/* Option 3
new Ajax.Updater(elm.parentNode, address, {
parameters: {
mblID: '2006121510341039',
}
*/
});
}
};
- I don't know what is the best way to do it ?
- I do not want to directly write the <script> tag in the page because
it may slow down the page loading.
- How can I have the response code from the Ajax request ?
- Should I set a userAgent ?
Thanks
--
It's actually a very nice way to include external scripts, since the
loading of a script (with src) has an effect on page load times, which
impacts tasks that run on page load and also visible to the user by
way of the browser's progress indicator.
You can create script nodes on the fly, with normal DOM-node creating
code and it works well in Firefox and IE6/7. I have not tested other
browsers.
This is the basic idea: http://pastie.textmate.org/144194
Note that the first thing that code does is look for a script include
already on the page that has included the same script, and if it is
found, then it is removed. This may be overkill, but is done to
prevent caching problems. If the same function that includes the
script is called multiple times, and you're expecting the script to be
refreshed, then you may want to append some type of no-cache parameter
(a time stamp) onto the URL, such as:
// do this just before the call to setAttribute('src', src)
src = ( src.match( /\?/ ) ? src + '&' : src + '?' ) + ( nocache ?
'nocache=' + new Date().getTime() + '&' : '' );
This little snippet has worked out very well for me, especially when
requesting external scripts that may take a while to load.
Have a great night.
-justin
I do not want to simply write <script> tag because like Justin Perkins
explain during the loading of the page when the browser see a <script>
tag it execute it. So if the server hang, the page slow down...
Scriptaculous use a handy way to write <script> tag. But it did it
- In the <head> or where it is declared
- Immediatly not onload
@Justin Perkins:
Thanks i'm going to try that. It is close to what I already tried. If
I remember the script loads but replace the full page. It's a little
bit weird.
I will try to send my question to MyBLogLog team. May be they already
know this issue.
Thanks
--
It's actually a very nice way to include external scripts, since the
loading of a script (with src) has an effect on page load times, which
impacts tasks that run on page load and also visible to the user by
way of the browser's progress indicator.
You can create script nodes on the fly, with normal DOM-node creating
code and it works well in Firefox and IE6/7. I have not tested other
browsers.
This is the basic idea: http://pastie.textmate.org/144194
Note that the first thing that code does is look for a script include
already on the page that has included the same script, and if it is
found, then it is removed. This may be overkill, but is done to
prevent caching problems. If the same function that includes the
script is called multiple times, and you're expecting the script to be
refreshed, then you may want to append some type of no-cache parameter
(a time stamp) onto the URL, such as:
// do this just before the call to setAttribute('src', src)
src = ( src.match( /\?/ ) ? src + '&' : src + '?' ) + ( nocache ?
'nocache=' + new Date().getTime() + '&' : '' );
This little snippet has worked out very well for me, especially when
requesting external scripts that may take a while to load.
The script you are including is probably doing document.write, which
is fine if the script is running in an IFRAME (I'm guessing you're
doing advertisements?). Try using DOM-manipulation techniques instead.
-justin
The script you are including is probably doing document.write, which
is fine if the script is running in an IFRAME (I'm guessing you're
doing advertisements?). Try using DOM-manipulation techniques instead.
Why do you include something like that through a remote script
include? Why can't you include that code in your local application's
javascript file? Is it for maintenance reasons?
-justin
Why do you include something like that through a remote script
include?
Why can't you include that code in your local application's
javascript file?
Is it for maintenance reasons?