Well it is complicated. I imagine you've edited the script a fair amount since you got it. I think that originally it was supposed to add the iframe onload. That's not reliable because many of the pages you will be cloning will have their own onload events that overwrite that. I'm guessing that may be why you added the document.write bit. That is if you did and if it happened like that. Others before you may have made changes. There are other issues, but I don't want to digress here.
But we cannot tell from javascript if it's a frameset until after the page loads and that's too late to do document.write. That's why I suggested editing the PHP script to tell that. The PHP script is still your best bet. Or, you can leave it as is. Like you say, at least they get to see you.
You could use this modified version of the script where I restore the onload, but do it in a way that cannot be overwritten:
Code:
(function(){
var movieWidth = 247;
var movieHeight = 400;
var pro_movie = null;
var PositionX = 100;
var PositionY = 100;
function init() {
if(document.getElementsByTagName('frameset').length){
//deal with the frameset here.
alert('ERROR!, The website you entered is made with frameset!\n' +
'You can still see me, but without your website');
location.href = 'http://www.coolwebmaster.net/members/kirsten/demo.html';
return;
}
var htmlBody = document.body;
var digi_div = document.createElement("div");
htmlBody.appendChild(digi_div);
digi_div.id = "pro_movie";
digi_div.innerHTML = '<iframe id="pro_movie" src="http://www.coolwebmaster.net/members/kirsten/demo.html" style="margin:0; padding:0; width:247px; height: 400px"; align="right" scrolling="no" frameborder="0" color: transparent; background-color:transparent; allowtransparency="true"></iframe>';
digi_div.style.position = "absolute";
digi_div.style.top = "-1000px";
digi_div.style.left = "-1000px";
digi_div.style.width = "247px";
digi_div.style.height = "360px";
digi_div.style.display = "none";
digi_div.style.zIndex = "10000";
var pro_movie = document.getElementById('pro_movie');
var moviePositionY = parseInt(getWindowScroll('y') + parseInt( ( (getWindowSize('y'))/100 ) * PositionY ) ) - (movieHeight/(100/PositionY) );
var moviePositionX = parseInt(getWindowScroll('x') + parseInt( ( (getWindowSize('x')-20)/100 ) * PositionX ) ) - (movieWidth/(100/PositionX) );
pro_movie.style.top = moviePositionY+'px';
pro_movie.style.left = moviePositionX+'px';
pro_movie.style.display = "block";
}
function getWindowSize(toreturn){
var position = new Array();
if (self.innerHeight) // all except Explorer
{
position['x'] = self.innerWidth;
position['y'] = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
position['x'] = document.documentElement.clientWidth;
position['y'] = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
position['x'] = document.body.clientWidth;
position['y'] = document.body.clientHeight;
}
if(typeof toreturn == "string")
return parseInt(position[toreturn]);
else
return position;
}
function getWindowScroll(toreturn){
var pro_movie = document.getElementById('pro_movie');
var position = new Array();
if (self.pageYOffset) // all except Explorer
{
position['x'] = self.pageXOffset;
position['y']= self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
position['x'] = document.documentElement.scrollLeft;
position['y'] = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
position['x'] = document.body.scrollLeft;
position['y'] = document.body.scrollTop;
}
if(typeof toreturn == "string")
return parseInt(position[toreturn]);
else
return position;
}
function setResize(){
pro_movie = document.getElementById('pro_movie');
if (pro_movie == null)
{
window.setTimeout('setResize()',10);
}
else
{
var moviePositionY = parseInt(getWindowScroll('y') + parseInt( ( (getWindowSize('y'))/100 ) * PositionY ) ) - (movieHeight/(100/PositionY) );
var moviePositionX = parseInt(getWindowScroll('x') + parseInt( ( (getWindowSize('x')-20)/100 ) * PositionX ) ) - (movieWidth/(100/PositionX) );
pro_movie.style.top = moviePositionY+'px';
pro_movie.style.left = moviePositionX+'px';
}
}
function setScroll(){
pro_movie = document.getElementById('pro_movie');
if (pro_movie == null)
{
window.setTimeout('setScroll()',10);
}
else
{
var moviePositionY = parseInt(getWindowScroll('y') + parseInt( ( (getWindowSize('y'))/100 ) * PositionY ) ) - (movieHeight/(100/PositionY) );
var moviePositionX = parseInt(getWindowScroll('x') + parseInt( ( (getWindowSize('x')-20)/100 ) * PositionX ) ) - (movieWidth/(100/PositionX) );
pro_movie.style.top = moviePositionY+'px';
pro_movie.style.left = moviePositionX+'px';
}
}
var addEvent = (function(){return window.addEventListener? function(el, ev, f){
el.addEventListener(ev, f, false);
}:window.attachEvent? function(el, ev, f){
el.attachEvent('on' + ev, f);
}:function(){return;};
})();
addEvent(window, 'load', init);
addEvent(window, 'resize', setResize);
addEvent(window, 'scroll', setScroll);
})();
If the site entered has a frameset, they will get the error message, but when you show up, it will no longer be in the lower right corner, rather near the top left. Some javascript on demo.html to detect if it is the top page could position the feature though. Or you could make a separate page with an iframe positioned properly and showing demo.html, and use that page's address instead of demo.html's in the location.href line in the above script.
This also makes me realize that none of this, as currently setup, is possible without javascript. So, if javascript is disabled, you should detect that and not offer this feature. Or at least have something next to input for the URL that says, "Javascript Required".
However, it should be possible to do all of this with PHP alone.
Bookmarks