Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,624 members, 7,809,304 topics. Date: Friday, 26 April 2024 at 07:33 AM

My First Post Of 2009 - A Frameset Question - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / My First Post Of 2009 - A Frameset Question (2050 Views)

10 Tips You Must Know & Have Before Applying For The Post Of An Admin On Webs / The Worst Site Of 2009? / First Quiz Of 2009 (2) (3) (4)

(1) (2) (Reply) (Go Down)

My First Post Of 2009 - A Frameset Question by yawatide(f): 6:55pm On Jan 01, 2009
As they say, practice what you preach.  In 2008, I preached that in 2009, we should all post things from which we can teach and/or learn.  This is my first of what promises to be many:

I recently revamped my new site, basically a collection of links to other actual news sites.  I decided, in order to maximize ad revenue, to go with frames.  I don't like frames but in order to boost site traffic and increase the potential of people clicking on ads, I have decided to cast my "hatred" of frames to the side for the time being, but I digress.

The idea is, the top frame (A) will have a header for my site while frame B has the website from which I am referencing for news.  I am done with that part though.  The issue arises with sites like punch where it seems they are detecting if they are being pulled up in a frame and if yes, they kick out of the frame into the main window, as if you accessed them directly.  I have created a workaround in those cases by using "taget="_blank" as I don't want my site to lose focus but I am figuring there is a way around this and hence my question:

Is there a solution out there that any of you know or have written than can check to see if thesite in question is sniffing for frames and if so, negate that sites's script, thus putting its site in frme B?  Call it a "frames detector detector".

I would appreciate your response(s).  Thanks in advance.
Re: My First Post Of 2009 - A Frameset Question by lagerwhenindoubt(m): 1:15pm On Jan 02, 2009
googled up this, could be useful, i simply lacked the courage to continue after the first few lines.

http://ha.ckers.org/xss.html

Should sniff out sniffers and I think its called Cross-Site Scripting

grin
Re: My First Post Of 2009 - A Frameset Question by OmniPotens(m): 1:35pm On Jan 02, 2009
Yawa,

Check this website to see if what is done there is exactly or close to what you want to do.

http://www.nigeriamasterweb.com/paperfrmes.html
Re: My First Post Of 2009 - A Frameset Question by lagerwhenindoubt(m): 2:10pm On Jan 02, 2009
@Omni.
it looks (on the surface) that the Punch website detects when it is being loaded via a frame and changes the frameset behavior to load parent _parent. which loads in the same window as the site where the load link request came form, so if you visited mynewsframe.com and clicked on punchng.com rather than load it in a frame on mynewsframe.com, it kicks it out and loads punchng.com so you will need to hit back button to get back to other newspaper sites.

@yawa, I do not know Javascript, but if there is a script doing this. you could do something i call function over-riding. when a script is loaded it is in the browser's session (in memory) if you know the function, you can simply write your own script to load after the one on punchng.com loads and return a null pointer. so nothing happens and the page is still loaded in the frameset as you intended. the XSS thing was just efizzy
Re: My First Post Of 2009 - A Frameset Question by yawatide(f): 4:03pm On Jan 02, 2009
Omni and larger, thanks.

Omni,
Yes, the site you showed is how my site works currently. That is the part in my post that I said I have since done. The issue I am having is what you will notice if you scroll the left column to where "punch" is and click the "punch" link. Notice what happens after a few seconds (hint: you are no longer on the site you sent me)

Larger,
Yes, the solutions you sent me are cross-site/dynamic scripting, very powerful concepts. I am liking your idea of using it to redefine the "punch" function that is causing the frame overriding. Having said that, I don't think it is efficent because there are 3 other good news sites that I also go to for news that have the same issue. Here are potential problems that I foresee with your approach:

1) What happens if Punch changes their function name tomorrow?
2) As I said, 3 other sites have the same behaviour. Am I to go searching on those sites for their overriding functions as well? If yes, refer to #1 above. Also let's not forget, I would then have to have separate function calls for each news site. Might be fine for 3 or 4 sites but what happens if I expand to 100 and 50 have the same behaviour?

I will thus use what I am using now which is to "target=_blank" on those specific sites for now while looking for a better solution. Having said that, I do really appreciate your answers. We have all definitely learned something from this.

By the way, there is a cool site that offers solutions to various javascript problems. Pretty much every perceivable javascript problem known to man is solved here and I am combing that site to see if they have a solution:
http://www.irt.org/script/script.htm

Good luck!
Re: My First Post Of 2009 - A Frameset Question by OmniPotens(m): 4:23pm On Jan 02, 2009
Thanks for that JavaScript link. At least, one issue I was trying to figure out was featured there so I needn't waste more time solving it when it has been solved there for me wink.

New year bonanza for me there tongue

I still have more issues to ask maybe here or in a new thread. Till then.
Re: My First Post Of 2009 - A Frameset Question by AbidemiA: 12:25am On Jan 03, 2009
You can achieve this by streaming first page of punch website, convert the streamed content to string, then pass the string as HTML code see how i implemented it here http://adten.net/News/index.aspx?tab=8 if this is what you need let me know the code behind is less than 20 lines.
Re: My First Post Of 2009 - A Frameset Question by Nobody: 1:36am On Jan 03, 2009
@yawa, i can help you a little there - there is a way you can forcefully pull data from other sites and display them on your site. A DHTML technique - the problem is that - it is not specific, i must configure my script per site - so that i can pull whatever aspect i need - but if you want to pull the entire page into your site - no problem - i should still be able to manage it.
You may want to take a look at this page: http://mwebng.net/?net=tt - it pulls a thread i created from nl to my site - via ajax - but if you click on any link in there, you will find yourself in nairaland - on the same thread. Though external links to other sites posted will open the relevant sites in a blank window as well. And it only costed me about 10 lines of php codes.
Re: My First Post Of 2009 - A Frameset Question by yawatide(f): 4:19am On Jan 03, 2009
Pretty interesting Abidemi and dhtml. How about each of you post your solutions on the forum so we all can take a peek and perhaps debate on the pros and cons of each as well as decide which is best?

Thanks for your input. Wow! 2009 is rolling to a good start, posts-wise grin
Re: My First Post Of 2009 - A Frameset Question by Nobody: 4:53am On Jan 03, 2009
I have done it already, please log on to http://mwebng.net/punch unlike abidemi, i chose to strip out all the javascript tags so that the page loads faster, and u can now either frame it or display it in a div, the example i am showing you pulls the punch site and displays it in a div that has been given a scroll bar and it loads in about 6 seconds on my own slow internet.
Re: My First Post Of 2009 - A Frameset Question by Nobody: 4:58am On Jan 03, 2009
index.php - the insertion code

<div style="width:500;height:600px;overflow:scroll">
<?php include "punch.php"; ?>
</div>


punch.php - the engine

<?php

$target="http://www.punchng.com/";
$contents=file_get_contents("$target"wink;

//resolve image
$contents = str_replace('src="/', 'src="$target', "$contents"wink;
$contents = str_replace("src='/", "src='$target", "$contents"wink;
$contents = str_replace("src='time.js'", "src='{$target}time.js'", "$contents"wink;

//i dont need script tags

//extract out the body tag
$i=strpos($contents,"<body"wink;$j=strpos($contents,'</body');

$contents=substr($contents, $i+22, $j-$i-22);

$search = array("src='images", "src='canada.gif","src='imeages.gif", "src='zenith.gif", "src='punch.gif","a href",'src="/',"<script","</script"wink;
$replace = array("src='{$target}images", "src='{$target}canada.gif","src='{$target}imeages.gif","src='{$target}zenith.gif", "src='{$target}punch.gif","a target='_blank' href","src=\"{$target}","<noscript","</noscript"wink;
$contents=str_replace($search, $replace, $contents);

echo "$contents";
?>



And when u are using it - please count the number of seconds and compare it with the other solution up there.

And if u want an ajax interface to it, just tell me, i made sure all my ajax scripts are well optimized, and work as good as jquery just faster because they are well optimized and are 2009 compliant!!!
Have fun.
Re: My First Post Of 2009 - A Frameset Question by OmniPotens(m): 5:42am On Jan 03, 2009
@Abidemi_A and dhtml

Is there no way to keep them entirely all framed without having them to pop out when you click on a link? I mean the Punch website?
Re: My First Post Of 2009 - A Frameset Question by AbidemiA: 6:54am On Jan 03, 2009
Here is the code

StringBuilder sUrl = new StringBuilder();
sUrl.Append("http://punchng.com/");

WebRequest oReq = WebRequest.Create(sUrl.ToString());
StreamReader sStream = new StreamReader(oReq.GetResponse().GetResponseStream());
StringBuilder sOut = new StringBuilder();
sOut.Append(sStream.ReadToEnd());
sStream.Close();

string abid = sOut.ToString();
abid = Regex.Replace(abid, "target='pollwindow'", ""wink;
abid = Regex.Replace(abid, "target='_blank'", ""wink;
abid = Regex.Replace(abid, "target='_self'", ""wink;
abid = Regex.Replace(abid, "href", " target='_blank' href"wink;

Literal1.Text = abid;

On my HTML page I have this
<base href="http://punchng.com/" />
<asp:Literal ID="Literal1" runat="server"></asp:Literal>

If you want to test for speed use this link http://adten.net/News/index2.aspx?tab=8

The first link I posted will take about x12 of the seconds that it is required to load the new link. Reason, I have 12 news sites that I am loading at the same time. Justification, you can navigate easily through the news sites without page reload until you are done with news section.

@Omnipotens,

It is possible, you can use regular expression to filter all links on the page, change the links values to other values that are directed to a frame on your page. I think this has legal implication , punch may sue you for circumventing the security they put in place to protect their content.

You will do the manipulation here

abid = Regex.Replace(abid, "href", " target='_blank' href"wink;

If you need to make it work for research purpose, mail me at abidemi_adio@yahoo.com

@dhtml,
When I clicked on links from your solution I got Error 404. Also, I noticed that you hard coded ref to some images, what happens when the names or refs of the images are changed? I think you can overcome this problems by setting the base ref of your content block to Punch domain.
Re: My First Post Of 2009 - A Frameset Question by OmniPotens(m): 7:25am On Jan 03, 2009
Thanks for the the code sample Abidemi_A.

As for the Punch, I'll let them to their security thing.
Re: My First Post Of 2009 - A Frameset Question by Nobody: 8:14am On Jan 03, 2009
Ok @Abidemi, u win - i only spent a few minutes on that - so i had to do some hardcoding - but have u seen my nairaland filter on http://mwebng.net/?net=tt there is not hard coding in that, and it displays beautifully.
But, dont let us start a debate on which one is better - asp.net or php - that will get very rough. On the bright side, i do asp.net too but i am yet to use it in a real life project.
Re: My First Post Of 2009 - A Frameset Question by yawatide(f): 1:26pm On Jan 03, 2009
First and foremost, I want to really thank Abidemi and dhtml for their posts. This is EXACTLY what I craved for in 2009 and beyond. This shows that we have matured from the "site review" days. Once again, thanks.

Since my site uses PHP, I would be tempted to use the dhtml approach. One looking at it further though, granted it is some pretty nifty code, I have a question:

$search = array("src='images", "src='canada.gif","src='imeages.gif", "src='zenith.gif", "src='punch.gif","a href",'src="/',"<script","</script"wink;
$replace = array("src='{$target}images", "src='{$target}canada.gif","src='{$target}imeages.gif","src='{$target}zenith.gif", "src='{$target}punch.gif","a target='_blank' href","src=\"{$target}","<noscript","</noscript"wink;
$contents=str_replace($search, $replace, $contents);

I assume that the $search part of the code has to do with the various ads on the punch site right? If yes, then does this imply that I have to do same for each paper that I access? If yes, imagine if I have 100 papers to peruse. That would be a nightmare.

Do I hear you say, "yawa na wa for you o! ok, if it bugs you that much, don't use that part"? Okay I hear you o! I don't have to but I just had a question okay? cool

Once again, thanks to the 2 posters.
Re: My First Post Of 2009 - A Frameset Question by Nobody: 1:51pm On Jan 03, 2009
The filter i created for nairaland on my site is only 10 lines and can pull any thread on nairaland into a site pictures and all once you specify the link to the thread - and without changing any codes. For punch however, there code is not well structured. Besides i was very sleepy as at the time i wrote that code - i will review it and give you something more reliable. i only studied the code to their home page. The code i gave you was just a sampling code - i will rewrite it later this night and repost it back on this thread. and i will tell you how to use it. Meanwhile, it will be good of you to give me a better idea of what precisely you want to do - i gather you want to frame the site [and do do you the links to open in same window or blank window?] - whatever, just paste it here - i will analyze and code later - i am tryin to finish a client job right now
Re: My First Post Of 2009 - A Frameset Question by Nobody: 9:39pm On Jan 03, 2009
I am working on the stuff now, please wait, 50% completed, packaging, , 80% tested and working,
90% working, is now pulling contents from multiple pages and displaying them in frames,
And it is 100% completed. Yes!!! I am Evil!!!!! hoo-hooo-haaaa-haaaa-haaa
Doing test running, and preparing to dump codes here, please wait, shit i missed my dinner!!
No problem, yawa can always post me another dinner -
[The Gismo]
You will be needing this small utility to encode your urls http://mwebng.net/utils/escape/ - nothing special just to escape your url
The demo is http://mwebng.net/punch/ - now to explain -
punch.php

<?php
$site="http://www.punchng.com/";
$target="http://www.punchng.com/";   //this is the specific page you want to get.

if(isset($_REQUEST['url'])!=""wink {$target=$_REQUEST['url'];}  //so you can point to urls within the puch website


//do not edit
$contents=file_get_contents("$target"wink;
$contents = str_replace("src='script", "src='{$site}script", "$contents"wink;
$contents = str_replace("='css", "='{$site}css", "$contents"wink;
$contents = str_replace("<body>", "<body><base href='{$site}'>", "$contents"wink;
$contents = str_replace("<body onload='init()'>", "<body><base href='{$site}'>", "$contents"wink;
$contents = str_replace("<script", "<noscript", "$contents"wink;
$contents = str_replace("</script", "</noscript", "$contents"wink;

$contents = str_replace("<SCRIPT", "<noscript", "$contents"wink;
$contents = str_replace("</SCRIPT", "</noscript", "$contents"wink;

echo "$contents";
?>



punch.html

<html>
<head>
<title>Punch Site Framed</title>
</head>
<body>
<table width="100%" border>
<tr><td>
Home Page<br>
<iframe src="punch.php" width=100% height=200></iframe>
</td></tr>
<tr><td>
Politics Page<br>
<iframe src="punch.php?url=http%3A//punchng.com/Maincat.aspx%3Fthecat%3DPOLITICS%0A" width=100% height=200></iframe>
</td></tr>


<tr><td>
The Health Page<br>
<iframe src="punch.php?url=http%3A//punchng.com/Maincat.aspx%3Fthecat%3DHEALTH" width=100% height=200></iframe>
</td></tr>


</table>
</body>
</html>


You can link to directly to any punch web page by using punch?url=sfsgsgwg because the urls can contain illegal characters like question marks is why i created utility  http://mwebng.net/utils/escape/

This now leads to the next issue of the links opening into the parent window - i only know of one hard way to solve that problem
- i am still considering,

However to make the links open in a blank window - u can add the line:

$contents = str_replace("a href", "a target='_blank' href", "$contents"wink;
into the php code above.


To make links open in the same window:
punch.php

<?php
$site="http://www.punchng.com/";
$target="http://www.punchng.com/"; //this is the specific page you want to get.

if(isset($_REQUEST['url'])!=""wink {$target=$_REQUEST['url'];} //so you can point to urls within the puch website


//do not edit
$contents=file_get_contents("$target"wink;
$contents = str_replace("src='script", "src='{$site}script", "$contents"wink;
$contents = str_replace("='css", "='{$site}css", "$contents"wink;
$contents = str_replace("<body onload='init()'>", "<body>", "$contents"wink;

$contents = str_replace("<body>", "<body onclick='jlink(event)' onerror='jlink(event)'><base href='{$site}'>", "$contents"wink;

$contents = str_replace("<script", "<noscript", "$contents"wink;
$contents = str_replace("</script", "</noscript", "$contents"wink;

//$contents = str_replace("a href", "a onclick=\"jlaunch(this.href);return false;\" href","$contents"wink;
$contents = str_replace("<SCRIPT", "<noscript", "$contents"wink;
$contents = str_replace("</SCRIPT", "</noscript", "$contents"wink;
$contents = str_replace("onmouseover=", "onchange=", "$contents"wink;
$contents = str_replace("onclick=", "ondbclick=", "$contents"wink;


print<<<end
<script>
var find="javascript:";
function jlink(e) {
targ= document.all ? e.srcElement : e.target;
alert(targ.parentElement.parentElement.innerHTML);
if(targ.tagName!="A"wink {return true;}
//swap target
with(targ) {if(href.indexOf(find)!=0) {href="javascript:jlaunch('"+escape(href)+"');"}}
return true;
}

function jlaunch(url) {
var re="punch.php?url="+escape(url);
location.href=re;
}

function parseLinks() {
links=document.getElementsByTagName("A"wink;
for(i=0;i<links.length;i++) {
targ=links[i];
with(targ) {if(href.indexOf(find)!=0) {href="javascript:jlaunch('"+escape(href)+"');"}}
}
}

function elog() {
return true;
}
onerror=elog;
</script>
$contents
<script>
parseLinks();
</script>
end;
?>



And not that you do not have to manipulate this code - the solution is now complete - i think
Re: My First Post Of 2009 - A Frameset Question by OmniPotens(m): 10:03pm On Jan 03, 2009
I love your skill of modifying your posts rather than making unnecessary random posts. Keep it up. This year smells lovely wink. A journey well began == half gone grin
Re: My First Post Of 2009 - A Frameset Question by Nobody: 3:31am On Jan 05, 2009
In the last post i made on this subject - it can load into frames and the links will open in the same frame.
Re: My First Post Of 2009 - A Frameset Question by yawatide(f): 10:23pm On Jan 05, 2009
Thanks guys for all your responses, granted I must confess it was a lil more than I was expecting wink

Having said that, dhtml, I have responded to your question here: https://www.nairaland.com/nigeria/topic-212088.0.html

It appears you have made a habit of asking me the same question all over the place tongue

That shouldn't take away from the solutions posted here though. To all, thanks once again.
Re: My First Post Of 2009 - A Frameset Question by Nobody: 10:29pm On Jan 05, 2009
iight lady - that will be all for now - i just needed to know i have not scripted in vain - i hate wasting scripts!!
Re: My First Post Of 2009 - A Frameset Question by yawatide(f): 10:56pm On Jan 05, 2009
blv me, u hvnt. Even if I don't use it now, blv me, there are ppl (much like u were, hmmm cool) who are visiting this thread and appreciating all you have done so far, though they probably won't say a word wink
Re: My First Post Of 2009 - A Frameset Question by OmniPotens(m): 11:06pm On Jan 05, 2009
Terrific observation!
Re: My First Post Of 2009 - A Frameset Question by Nobody: 1:45pm On Jan 06, 2009
I know that - I am used to it - it is just a pity that i have been in a white forum - all this years - flowing along with them - and forgetting my brothers and sistas here - anyways - i am only one person - i will do as much of free service i can do - and balance it with my own personal life - i just love helping ppl whether they appreciate it or not is not what is important - there are those that appreciate and there are those who do not - i have settled that issue with myself some few years back.
Re: My First Post Of 2009 - A Frameset Question by yawatide(f): 3:53pm On Jan 06, 2009
uhhmm, and what's the difference b/w white students and black students? Aren't we all, at the end of the day, human beings? undecided
Re: My First Post Of 2009 - A Frameset Question by Nobody: 11:54pm On Jan 06, 2009
U answer yourself, i have more preference for my fellow blacks anyway. Lemme not say more than dat just so i dont break forum rules.
Re: My First Post Of 2009 - A Frameset Question by OmniPotens(m): 4:39am On Jan 07, 2009
Cooooooooooooooooooooourt!

TOPIC: My First Post Of 2009 - A Frameset Question

Don't wake sleeping dogs here. We are mixed in here so don't let that thing on your minds creep in.

All animals are equal but with different experiences and developments grin
Re: My First Post Of 2009 - A Frameset Question by lagerwhenindoubt(m): 3:08pm On Jan 08, 2009
man i am so out-dated grin
Re: My First Post Of 2009 - A Frameset Question by OmniPotens(m): 2:18am On Jan 09, 2009
lagerwhenindoubt:

man i am so out-dated grin

Out-dated as in
Re: My First Post Of 2009 - A Frameset Question by Nobody: 8:52pm On Jan 10, 2009
***Wondering who will win, i still have a chance i hope! ***
Audience cast your votes O. I have already prepared my own quiz - when i get back to my laptop after my leave next week i will post it!!
Re: My First Post Of 2009 - A Frameset Question by lagerwhenindoubt(m): 1:00pm On Jan 12, 2009
out-dated as in. if you know how much junk code i would have had to patch to get to this level of coming at a solution as the ones presented here, you will ban me for life. grin

(1) (2) (Reply)

Web Design Training In ILORIN.Learn how to make money online,on facebook,twitter / I Want To Link An Image To Something. How Do I Do That? / Design And Develop Your Website At Your Pocket Cost With Us Here

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 79
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.