Insert an ajaxified Webpart into an existing MOSS site - javascript

I need to code a webpart which purpose is to asynchronously fetch some documents and display them into an existing page. Unfortunately I have to face a lot of rescritcions and my struggle to find a solution seems useleess so far.
1) I cannot use Microsoft asp.net ajax
2) I must use Jsonp because the called service (page, whatever...) is outside the site's domain. That's not a big problem.
3) I have no possibility to alter the existing page code, so I cannot reference an external library such as JQuery.
4) For the same reason I have no possibility to call my methods on the window.onLoad event, so here the question is: how can I be sure that everything is correctly loaded before triggering my ajax call?
5) Since several instances of the same webpart can be placed into the same page, can there be some possible conflicts among the various js functions?

D'oh
D'oh #2
jQuery is just a wrapper for native JavaScript calls. If you can, get them to waive this restriction because if you're doing anything remotely complex you're going to go insane over browser compatibility.
Use _spBodyOnLoadFunctionNames.push(functionName) to accomplish this.
Depends entirely on the JS coming in. We'd need more clarification.

Can't you just call the 3rd party page using server-side code (e.g., WebClient)? You may have to adjust the site's trust levels for this.
For client-side, I believe you can still "inject" the jQuery code into the markup.
Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
document.write(unescape("%3Cscript src='/path/to/your/jquery' type='text/javascript'%3E%3C/script%3E"));
}
</script>

What about using a page viewer web part to display the page that is hosted elsewhere (ie not on your SharePoint server)? That page could retrieve the documents for you.

Related

JavaScript Privilege Limitation

I am using a partner javascript on my website.
We are adding it by importing by tag.
I wish to limit the access capabilities of the use of this javascript.
How can I manage it's access to different site location and data?
Edit: Additional info
(note: my question is more security handling):
adding script for example:
<script async src='http://www.somewhere.com/somefunctionality.js'></script>
<script>
func1('param1', 'param2');
func2('param3', 'param4');
</script>
The js script is available in the basic site template, so it will available easily in all the site.(e.g. calling it's functions)
But, I wan't to limit his ability to access some areas/data of the site. or perform any unauthorized actions.
Without moving it.
is it possible?
Thanks,
Js
You can run the external library inside of Google Caja. It's designed exactly for this purpose.

Can Googlebot crawl javascript generated content?

We have a web app that its content generated by javascript. Can google index those pages?
When we investigate this issue we always found solutions from old pages about using "#!" in links.
In our app the links are like this:
domain.com/paris
domain.com/london
When we use these kind of links, javascript populates content.
Is it wise to use HTML snapshot or do you have any other suggestions?
Short answer
Yes they can crawl JavaScript generated content, as long as you are using pushstates.
Detailed answer
It depends on your setup. Google and Bing CAN crawl javascript and AJAX based content if your are using pushstates. If you do they will handle content coming from AJAX calls, updates to page title or meta tags using javascript, and in general any such things.
Most frontend frameworks like Angular, Ember or Backbone already works with pushstates so in these cases you don't need to do anything. Check whatever system you are using to see how they do things. If you are not using pushstates you will need to implement it on your own or use the whole escapted_fragment html snapshot deal.
So if you use pushstate then yes, search engines can crawl your page just fine. If you don't then no, you will need to implement pushstates or do HTML snapshots.
Bonus info - Unfortunately Facebook does not handle pushstates, so the facebook crawler needs either non-dynamic og-tags or HTML snapshots.
"Generated by JavaScript" is ambiguous. That could mean that you are running a JS script on the server or it could mean that you are making an AJAX call with a JS API. The difference appears to matter as far as Googlebot is concerned. But you don't have to take my word for it, as there is empirical proof of what Googlebot will and won't currently cache as far as JavaScript content in the form of live experiments using both the XMLHTTPRequest API and the Fetch API. So, as you can see, server-side rendering is still going to be the best way to go for SEO.

Wordpress Widget on a page not using Wordpress

I use a wordpress blog format for the news section of my website but not the main part and I want to have a"most recent" widget drawing from the wordpress section but displaying on a page that is not using the blog it is written mostly in html and javascript. Is this possible and if so does anyone have any examples they could point me to?
Thanks!
I don't think it's possible - the Widget API is loaded somewhere in the middle of the WordPress loading process so you need a PHP rendering engine loading the entire WP and getting the widget code evaluated at the end. You will need some PHP to get the data from the database or at least AJAX code calling to external scripts that pull posts from the MySQL database.
It may be possible with an iframe, but I (as would most developers) highly advise against that. W3C compliance with iframes can be tricky, but if you're not worried about that then give it a go. On second thought, iframes wouldn't even be a viable option. Just pull the RSS in to your HTML pages using something like this (http://www.htmlgoodies.com/beyond/css/displaying-rss-feeds-with-xhtml-css-and-jquery.html) from HTMLGoodies.com.
Another alternative could be to use a method outlined by FLD Trace here: http://www.fldtrace.com/wordpress/display-latest-post-outside-of-wordpress-with-json-and-jquery, and showcased here: http://www.fldtrace.com/lab/jsonAPI.html.
I've used it before with mild success on a few projects, and styled the FLDT widget accordingly. Be sure to give credit where credit is due if you use this and it fits the bill of what you're looking for--though I don't see any licensing restrictions for FLD Trace's method.

file upload using ajax

I am looking for an AJAX method that can be used to file upload.
It will be super if I find a function that uses Prototype + Script.acul.us
File uploads are not possible using pure Ajax, because Javascript can't get direct access to the local file.
Tools like the jQuery form plugin work around this by generating an invisible iframe on the fly, and submitting to that.
There probably is a Prototype based, or framework independent solution for this as well.
there is no native ajax support for this, however Uploadify does a workaround using flash (uses jquery but is able to be used with other api's since 2.0)
http://teamco-anthill.blogspot.com/2009/01/ajax-progress-indicator-with-prototype.html
?
As others have pointed out, javascript is not able to asynchronously upload files (otherwise javascript enabled sites could steal any file off your harddrive). The best approaches are:
A flash uploader, as already suggested
Or simulate an Ajax request using an iframe
The iframe approach means that it's the iframe which reloads, instead of the page displayed to your users, so that to the end user, the experience looks as if it's Ajax.
If you're using rails, which I gather you might be due to using prototype and scriptaculous, there's a plugin available which handles the tricky bits of this approach for you called responds_to_parent, It's been ages since I implemented this in a rails app myself, but step 6 from this blog looks like a good example of how to use it.

How to create embeddable gadget with Javascript and PHP?

I'm programming in Javascript and PHP. I've created a simple website that allows to fill in a quizz and get result. Now I would like to give users opportunity to embed this quizz on their website. How to do this? It should work in some near manner like Google Gadgets, Adsense and that: that so when someone will put my html code (with JS?) on their websites, quizz will display and work on their site.
Do you know any tutorials about doing such things or tips for me how to start searching and learning about it?
The easiest way, which is also best performance- and security-wise, is to use <iframe>. Just create small version of your page for embedding.
<script> is loaded synchronously and gets access to site's cookies, so it's not a good solution for embedding.
If you just ask your users to embed <script> in place where they want the gadget to be, you'll be able to generate markup with document.write (easy, works in HTML only).
A better way is to ask users to invoke function from your script that inserts code into selected DOM node (using W3C DOM). This allows smarter webmasters to load script asynchronously. SWFObject is designed like that.
If you need to use PHP you could tell your server to parse a .js file as PHP:
<Files quiz.js>
ForceType application/x-httpd-php
</Files>
In the quiz.js file, use PHP code to retrieve questions from a database or whatever. Then, set mime-type headers to Javascript and output Javascript code.
Though as porneL says, using an iframe is simpler. That's what Google Gadgets does.

Categories