seedg
seedg

Reputation: 21935

Using jQuery load function as an absolute path

I have several pages and these pages can be accessed either directly, or from an iFrame. The part where the page can be loaded as an iFrame is used for some functionality that I need.

The problem is, that when I use the .load() function in jQuery, the stylesheets, scripts, some images, etc are not being found because the .load() tries to load everything as a relative path from where it is called.

I need to load the pages in the iFrame kind of like a snapshot, which means that they should behave the same way as if they were accessed directly.

Trying to summarize, this is the problem:

The file is located as follows:

http://localhost/www/folders/myfolder/myfile.html

The index file from where the .load() function is called is in the root, i.e.

http://localhost/www/index.php

myfile.html contains links like:

css/style.css
js/script.js

There, these are located at:

http://localhost/www/folders/myfolder/css
http://localhost/www/folders/myfolder/js

Therefore, when the .load() function loads the file from the root folder, these are not found because they are read as follows:

http://localhost/css/ instead of http://localhost/folders/myfolder/css

How can I get around this?

Many thanks

Upvotes: 1

Views: 2550

Answers (3)

mike
mike

Reputation: 302

Sounds like in your myfile.html, you just need to add "folder/myfolder/" to your stylesheet and script paths.

Upvotes: 0

Caspar Kleijne
Caspar Kleijne

Reputation: 21864

you could add a base tag to your loaded page with jQuery

      $("head").append("<base href="http://localhost/folders/myfolder/" />");

depending on the loading order you should play with this. (I am not sure if the css needs to be loaded BEFORE or AFTER this has been set)

Upvotes: 2

Poonam
Poonam

Reputation: 4631

I think you can try this,

<?php
define('file_path_css','folder/myfolder/css');

include file_path_css;

?>

this might work..

Upvotes: 0

Related Questions