Recent Topics

1 Oct 24, 2006 17:43    

After quite searching, i've found out a little code here (http://forums.b2evolution.net/viewtopic.php?t=2254) and immediately applied.. Guess what? every single link in the site displayed in a new window -which was not really prefered for me. so i made a hack which is a little bit of javascript..


<script>
	var sitename = 'http://www.yoursite.net/';
	for (var i=0; i<=(document.links.length-1); i++) {
		if (document.links[i].href.substring(0,sitename.length) ==sitename.substring(0,sitename.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";
		}
	}
</script>

code should be placed just before the </body> tag, so that it checks every single link that is placed in the page.

While checking links on the page, the script looks for the href of the link and if it goes to another site, it displays it in a new window.

And of course you'll need a showsite.php in the root of your blog..

code for it is here also :
SHOWSITE.PHP:


<?php
$Site_Title = $_GET["title"];
$Site_URL = $_GET["siteURL"];
$b= $_GET["blog"];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> <?php echo $Site_URL ?></TITLE>
<META NAME="Generator" CONTENT="">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<FRAMESET rows="30,100%" frameborder=2">
	<FRAME NAME="TopF" SRC="http://www.yoursite.net/site.php?B=<?php echo $b ?>&URL=<?php echo $Site_URL ?>" />
	<FRAME NAME="MainF" SRC="<?php echo $Site_URL; ?>"/>
	<NOFRAMES></NOFRAMES>
</FRAMESET>
</HTML>

The page is the loader page, so you'll need another page (for header only) .. here it is :

SITE.PHP


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=windows-1254">
</HEAD>
<BODY>
	<p>You're visiting a site out of my site, out of my blog <b><?php echo $_GET["B"] ?></b> Please close this window to go back.</p>
</BODY>
</HTML>

Of course, any comments will be appreciated :) If you need further help, post your questions here, I'll be happy to help you.

2 Nov 06, 2006 09:35

: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.

3 Nov 06, 2006 19:23

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! :)

4 Nov 06, 2006 20:24

I'll sure keep an eye here !

-- Watch list: On --

5 Dec 14, 2006 18:29

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!

6 Dec 14, 2006 19:04

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 :)

7 Dec 14, 2006 19:08

But if you want to include many sites in the array, we should think of a more revised code. Hope this helps.

8 Dec 17, 2006 12:18

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!

9 Dec 17, 2006 14:44

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 :)

10 Jan 01, 2007 12:20

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 ..

11 Jan 01, 2007 12:24

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.

12 Jan 01, 2007 12:27

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.

13 Jan 01, 2007 12:33

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.

14 Jan 04, 2007 18:38

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

15 Jan 16, 2007 04:30

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

16 Jan 27, 2007 11:23

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


Form is loading...