Lady_M
asked on
Passing relative URL variables to include files
Hello
I hope I can explain this clearly.
Okay, I have a global javascript function held in a global directory. Basically it takes a url passed into it when a person clicks on a tab and via Ajax Updater loads that url into a text area.
So I have this tabbed widget which uses this function which needs to be included in lots of different microsites in different directories.
So,
========The widget looks like this:==========
<div id="aNiceWidget">
<ul>
<li><a href="#" onclick="return populateIBox('parent_micro site_root/ _includes/ iBox_stuff 1.inc', this);">Stuff1</a></li>
<li><a href="#" onclick="return populateIBox('parent_micro site_root/ _includes/ iBox_stuff 2.inc', this);">Stuff2</a></li>
</ul>
<div id="iBoxtext">Some info is coming any day now</div>
</div>
* Where parent_microsite_root = the root of the microsite page that has the widget in it.
And
=========The global function looks like this:==============
var theObj=null;
function populateIBox (serverPage, obj){
theObj = obj;
var objID = "iBoxText";
new Ajax.Updater(objID, serverPage, {method:'get', onComplete:function(){
}
}
//load initial page into the widget
Event.observe(window, 'load', function(){ populateIBox('relevant_par ent_micros ite_root/_ includes/i Box_stuff1 .inc', null); });
So my question is this:
Because this is a widget that will sit in lots of different files I cannot put absolute urls in there. I need it to get the page's parent url and then tag on the rest of the relative path to the end.
I also need the initial load in the javascript to do the same thing.
In other words I need for both the widget and the javascript to recognise the microsite's parent url as a variable.
I have this variable available in each microsite: <?php $doc_root = $_SERVER['DOCUMENT_ROOT']; ?>
Can I use that?
Thanks if you can help.
I hope I can explain this clearly.
Okay, I have a global javascript function held in a global directory. Basically it takes a url passed into it when a person clicks on a tab and via Ajax Updater loads that url into a text area.
So I have this tabbed widget which uses this function which needs to be included in lots of different microsites in different directories.
So,
========The widget looks like this:==========
<div id="aNiceWidget">
<ul>
<li><a href="#" onclick="return populateIBox('parent_micro
<li><a href="#" onclick="return populateIBox('parent_micro
</ul>
<div id="iBoxtext">Some info is coming any day now</div>
</div>
* Where parent_microsite_root = the root of the microsite page that has the widget in it.
And
=========The global function looks like this:==============
var theObj=null;
function populateIBox (serverPage, obj){
theObj = obj;
var objID = "iBoxText";
new Ajax.Updater(objID, serverPage, {method:'get', onComplete:function(){
}
}
//load initial page into the widget
Event.observe(window, 'load', function(){ populateIBox('relevant_par
So my question is this:
Because this is a widget that will sit in lots of different files I cannot put absolute urls in there. I need it to get the page's parent url and then tag on the rest of the relative path to the end.
I also need the initial load in the javascript to do the same thing.
In other words I need for both the widget and the javascript to recognise the microsite's parent url as a variable.
I have this variable available in each microsite: <?php $doc_root = $_SERVER['DOCUMENT_ROOT'];
Can I use that?
Thanks if you can help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Isisagate.
Sorry can you clarify what you want me to do to my global.js file?
You say I need to save it as global.php and include this variable in there:
var parent_root = '<?= $_SERVER['DOCUMENT_ROOT']; ?>';
If so, won't that variable have the value of the php file's parent, rather than the microsite which is calling it?
Sorry can you clarify what you want me to do to my global.js file?
You say I need to save it as global.php and include this variable in there:
var parent_root = '<?= $_SERVER['DOCUMENT_ROOT'];
If so, won't that variable have the value of the php file's parent, rather than the microsite which is calling it?
ASKER
I don't know php by the way.
ASKER
Can i use ajaxpack.basedomain ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay I'll try to explain.
On the website page there will be a box, it has three tabs at the top and when people click on the tabs they will see three different blocks of text loaded into the box. Those three blocks are specific to the particular site they are on. E.g. "This site's copyright info is such and such", "This site is about such and such" and "Our company is about such and such".
Tthe organisation I'm building this for actually manages about 40 different sites all on the same host server, but with different domains. They all need this same box so I want to reuse it as an include file.
Each site has exactly the same sub directory structure, the only thing that is different between them all is their domain. So one site would have these three pages to load into its tabbed box:
www.site-one.com/_infofortabbedbox/page1.html
www.site-one.com/_infofortabbedbox/page2.html
www.site-one.com/_infofortabbedbox/page3.html
and another would have these three pages to load into its tabbed box:
www.site-two.com/_infofortabbedbox/page1.html
www.site-two.com/_infofortabbedbox/page2.html
www.site-two.com/_infofortabbedbox/page3.html
So I wanted to make the tabbed box an external object and have it call an external javascript to make it work.
So in each site, I have the javascript file included in the head. And in the body I have the tabbedbox.inc included as an external file.
I then need that included tabbed box to pick up the domain of the page it is included *in* (ie, www.site-one.com or www.site-two.com).
rather than its own domain (www.host.com/_global/_includes/)
or the domain of the javascript (www.host.com/_global/_scripts/)
I tried using a variable in the object, but I'm really not too sure how this works, and whether variables are picking up the page domain, or the object's domain or in fact the javascript's domain. What I need is the page's domain. I have the second problem of the javascript loading an initial page, so it also need's the page's domain.
I tried a few of the obvious things with no luck and I'm not sure if it's my syntax which is wrong or whether it's more fundamental.
Could somebody explain to me the process and if possible the correct syntax?
Thanks
On the website page there will be a box, it has three tabs at the top and when people click on the tabs they will see three different blocks of text loaded into the box. Those three blocks are specific to the particular site they are on. E.g. "This site's copyright info is such and such", "This site is about such and such" and "Our company is about such and such".
Tthe organisation I'm building this for actually manages about 40 different sites all on the same host server, but with different domains. They all need this same box so I want to reuse it as an include file.
Each site has exactly the same sub directory structure, the only thing that is different between them all is their domain. So one site would have these three pages to load into its tabbed box:
www.site-one.com/_infofortabbedbox/page1.html
www.site-one.com/_infofortabbedbox/page2.html
www.site-one.com/_infofortabbedbox/page3.html
and another would have these three pages to load into its tabbed box:
www.site-two.com/_infofortabbedbox/page1.html
www.site-two.com/_infofortabbedbox/page2.html
www.site-two.com/_infofortabbedbox/page3.html
So I wanted to make the tabbed box an external object and have it call an external javascript to make it work.
So in each site, I have the javascript file included in the head. And in the body I have the tabbedbox.inc included as an external file.
I then need that included tabbed box to pick up the domain of the page it is included *in* (ie, www.site-one.com or www.site-two.com).
rather than its own domain (www.host.com/_global/_includes/)
or the domain of the javascript (www.host.com/_global/_scripts/)
I tried using a variable in the object, but I'm really not too sure how this works, and whether variables are picking up the page domain, or the object's domain or in fact the javascript's domain. What I need is the page's domain. I have the second problem of the javascript loading an initial page, so it also need's the page's domain.
I tried a few of the obvious things with no luck and I'm not sure if it's my syntax which is wrong or whether it's more fundamental.
Could somebody explain to me the process and if possible the correct syntax?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi all
thanks for the replies, I haven't forgotten about this issue, I've just had alot of urgent stuff to get done. i will take a look at this this week and get back to you.
thanks for the replies, I haven't forgotten about this issue, I've just had alot of urgent stuff to get done. i will take a look at this this week and get back to you.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
<div id="aNiceWidget">
<ul>
<li><a href="#" onclick="return populateIBox('<?= $_SERVER['DOCUMENT_ROOT'];
<li><a href="#" onclick="return populateIBox('<?= $_SERVER['DOCUMENT_ROOT'];
</ul>
<div id="iBoxtext">Some info is coming any day now</div>
</div>