As I stated in a comment to your question, the reason your Slick Slider plugin stops working after you load the other document is because the other document is re-including the jQuery library into your top-level browsing context.
jQuery plugins make themselves accessible by defining a new method and then attaching it to the jQuery.prototype
(aliased as jQuery.fn
) object.
When you include the jQuery library into your document via a script tag, you can call console.log(jQuery.fn);
and you will see an object with all of the convenient methods that make up the jQuery library.
After you have similarly included the Slick Slider library, you can again call console.log(jQuery.fn);
and you can find that it has a method property named slick
.
The problem is that when you load the document that resides at url
that document is inserting a fresh script
tag into your parent document whose src
is jQuery. This causes a fresh loading of the jQuery library which obliterates your initial instance. If you call console.log(jQuery.fn.slick);
at this point, you will find that it is undefined
.
I have never before seen an entire HTML document (as opposed to a snippet of HTML) loaded into a div
of another document. This is inserting elements into the body of your top-level document that should not be there, like <head>
and <body>
. I am actually surprised that this is causing so few issues for you.
The way documents are normally nested within other documents is by the use of an iframe. The document within the iframe will be its own sandbox, and its styles and scripts will not be in conflict with those in the parent frame.
You could implement an iframe into your project by replacing $('.frame').load(url);
with something like the following:
var $iframe = $('<iframe />', {
src: url,
style: 'height:100%; width:100%;'
});
$('.frame').html($iframe);