2 sylv Nov 06, 2006 09:35

Well, i'm glad you've liked it! :)
In fact, there are so many things that should be done, after testing them on my site, i'll send them here of course! :)
I'll sure keep an eye here !
-- Watch list: On --
This code is awesome!
But could you give me a hint what I have to do to exempt also links to an other specific page from opening in a new page?
For explanation:
I want to open links to http://blogs.mysite.net and also links to http://sub.mysite.net in the same window.
Links to external pages should be openend in a new page.
Thanks!
Well, this can be done in several ways, but..
let me think :
You have several sites -which are in the same domain..
let's get our hands dirty! :)
First, we have to define an array :
//changed the sitename to sitenames because it will contain many addresses and it became an array.
var sitenames = new Array (
"http://site1.mysite.net/",
"http://site2.mysite.net/",
"http://siten.mysite.net/",
"http://othersite.bothersite.com"
);
for (var i=0; i<=(document.links.length-1); i++) { // main loop
for (var n=0; n<=sitenames.length-1; n++) { // secondary which will loop in "sitenames" array
if (document.links[i].href.substring(0, sitenames[n].length) == sitenames[n].substring(0,sitenames[n].length)) {
document.links[i].target ="_self";
} else {
var hr = sitename+"showsite.php?blog=<?php $Blog->disp('name','htmlattr');?>&siteURL="
var qr = document.links[i].href;
document.links[i].href = hr.replace(/ /g,'+') + qr;
document.links[i].target = "_blank";
} //if..else
} //for n
} //for i
if the code doesn't work, let me know, i'll revise the code again :)
But if you want to include many sites in the array, we should think of a more revised code. Hope this helps.
Wow, thx for the fast reply!! :)
But, unfortunately it doesn't work on my page. :-(
Every link is opened in _self. I'm sorry, I could not figure out why. I have to admit, I absolutely don't have a clue about php... :-(
Thank you!
I'll try it on my site and if there'll be any changes, I'll let you know the new code. Check back again :)
Hello again..
Code slightly changed.
var baseTarget = "http://www.gundebir.net/"; //base site which shows links.
var sitenames = new Array (
"www.osite.com",
"www.gundebir.net",
"www.susite.com",
"www.aaa.com/bb"
);
The baseTarget defines the main target for the displaying site. In this case, my domain is displayed there.
The array which sitenames are held changed. Now, if you have subdirectories that you want to exclude also is excluded. like "aaa.com/bb"
and ..
we have a new function which will check the links if they are in the sitenames array :
function inArray(siteToCheck, subToCheck) {
var n=0;
var stat = false;
while ((n<sitenames.length-1) && (!stat)) {
if (sitenames[n].indexOf("/") > -1) {
if (sitenames[n] == siteToCheck+'/'+subToCheck) {
stat = true;
}
} else {
if (sitenames[n] == siteToCheck) {
stat = true;
}
}
n++;
} //while
return stat;
}
The function checks the given string(s) if they're in the list or not.
and the main loop..
var lynx = document.links;
for (var i=0; i<= (lynx.length-1); i++) { //main loop
splitLynx = lynx[i].href.split("/");
splitSub = splitLynx[3].split("?");
if (inArray(splitLynx[2],splitSub[0])) {
document.links[i].target ="_self";
} else {
var hr = baseTarget + "showsite.php?blog=Klavye Mahsulleri Ofisi&siteURL="
var qr = document.links[i].href;
document.links[i].href = hr.replace(/ /g,'+') + qr;
document.links[i].target = "_blank";
}
} //main loop
:)
The code works in my site, gundebir.net . just view the source and look before the </body> tag.
Here's the complete script :
<script>
var baseTarget = "http://www.gundebir.net/"; //base site which shows links.
var sitenames = new Array (
"www.osite.com",
"www.gundebir.net",
"www.susite.com",
"www.aaa.com/bb"
);
function inArray(siteToCheck,subToCheck) {
var n=0;
var stat = false;
while ((n<sitenames.length-1) && (!stat)) {
if (sitenames[n].indexOf("/") > -1) {
if (sitenames[n] == siteToCheck+'/'+subToCheck) {
stat = true;
}
} else {
if (sitenames[n] == siteToCheck) {
stat = true;
}
}
n++;
} //while
return stat;
}
var lynx = document.links;
for (var i=0; i<= (lynx.length-1); i++) { //main loop
splitLynx = lynx[i].href.split("/");
splitSub = splitLynx[3].split("?");
if (inArray(splitLynx[2],splitSub[0])) {
document.links[i].target ="_self";
} else {
var hr = baseTarget + "showsite.php?blog=<?php $Blog->disp('name','htmlattr');?>&siteURL="
var qr = document.links[i].href;
document.links[i].href = hr.replace(/ /g,'+') + qr;
document.links[i].target = "_blank";
}
} //main loop
</script>
put it just before the </body> tag.
Hi again!
This code works great! Thank you very much!!
I just had to fiddle about a little with the sitenames in the array, but now it works perfectly!
Thanks again!
Florian
Excellent script... Thanks. I have been going through page by page to find out where I could change the titles....
One little bug I see... I have a couple of titles with a ' in it... Like Broc's Links. The ' will make the script fail and no site loads in the new window.
Can this be fixed?
Broc
BrocLee wrote:
Excellent script... Thanks. I have been going through page by page to find out where I could change the titles....
One little bug I see... I have a couple of titles with a ' in it... Like Broc's Links. The ' will make the script fail and no site loads in the new window.
Can this be fixed?
Broc
Of course BrocLee..
try "Broc\'s Links" instead Broc's Links ;)
this is the default behaviour for javascript, it uses (') sign for strings. To overcome this, you can use (\').
best regards,
Yumurcak
:lol: I LOVE IT :lol:
Especially the little window saying: you are visiting a page out of my blog (blog name included) !
It's super easy to install, takes 2minutes in all, and the functionality is just what I was looking for.
BRAVO !!!!!!!
And thank you for sharing.
PS
In the beginning, I was redirected to mysite.net, but I soon realised I had to edit the php files and _main.php.