Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Cross domain problem for iframe
Old 08-05-2006, 06:32 AM Cross domain problem for iframe
Junior Talker

Posts: 4
Name: Sadanandam
Trades: 0
Hi,

I have an image in an IFrame and the Iframe height and width are same as the image. When I mouse over the
image, it expands above it(upwards). Now I want to resize the iframe to the size of image i.e., upwards (enlarged image size is fixed).

This is working fine when they are in same domain.

When my iframe and its source file are in different domains and if I try to change the dimensions of iframe from the source file using window.frameElement it is giving 'access denied' problem.

Here is the code for source file (expand_overlay_top.html):
HTML Code:
<html lang="en">
<head>
<title>image over text</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
function GetElementPostion(theElement,addTop)
{

    var selectedPosX = 0;
    var selectedPosY = 0;

    var myiframe = theElement ;
    
    while(theElement != null)
    {
        selectedPosX += theElement.offsetLeft;
        selectedPosY += theElement.offsetTop;
        theElement = theElement.offsetParent;
    }
    myiframe.style.top = selectedPosY + addTop;
    myiframe.height = myiframe.height - addTop;
}

 
//-->
</SCRIPT>

<style type="text/css">
<!--
.banner {
    position:absolute;
    top:-240px;
    left:0px;
   scrollbars:no;
}




.1111_norm { height:60px; 
                             top:0px
                            }
.11111_over { height:300px;
                            top:-240px
                            }
.1111_over_frame{ height:300px; top:0px}
.1111_over_norm{ top:0px}
-->
</style>


<div style="position:relative;width:468px;height:60px" >
<a href="http://www.somesite.com" id='img1'><img src="468x60b.gif" name=some_img class=1111_norm border=0
style="display:block;position:absolute;width:468px;overflow:auto;"
onMouseover="this.className='11111_over'; if(window.parent != window) { this.className='11111_over_frame'; GetElementPostion(window.frameElement,-240); this.src='468x300b.gif';}" 
onMouseout="this.className='1111_norm';if(window.parent != window) {  GetElementPostion(window.frameElement,240); this.src='468x60b.gif'; } ">
</a>

</div>


</body>
</html>
Here is the code for iframe:
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

</HEAD>

<BODY>
2.Here's some text<br>
and some more<br>
3.Here's some text<br>
and some more<br>
4.Here's some text<br>
and some more<br>
5.Here's some text<br>
and some more<br>
2.Here's some text<br>
and some more<br>
5.Here's some text<br>
and some more<br>
2.Here's some text<br>
and some more<br>
5.Here's some text<br>
and some more<br>
25.Here's some text<br>
and some more<br>
<iframe name="banner" id="banner"  src="expand_overlay_top.html" height=60  width=468 scrolling=no hspace=0 vspace=0 frameborder=0 marginheight=0 marginwidth=0 style="position:absolute;background:blue;z-index:1;">
</iframe>
</BODY>
</HTML>
So, anyone has any idea on this ?


Thanx,
Sadanandam.
sadanandam is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-05-2006, 01:09 PM Re: Cross domain problem for iframe
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
It's a security issue, you can't target frames/windows/pages from other domains. So you couldn't do something like open an eBay login window and change the form action to go to another server. Put both pages on the same server to fix the problem. Maybe try putting the iframe in there as the full height, but wrapped in a DIV with overflow:hidden, then change the div's height?

Last edited by funkdaddu; 08-05-2006 at 01:11 PM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-05-2006, 01:29 PM Re: Cross domain problem for iframe
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Just like funkdaddu said it's a big security issue. If all you are putting into the iframe why use the iframe at all? Why not just put the image inside a div which will resize itself to the image or set the size on the div if you need to for your layout and use the overflow property.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 08-05-2006, 03:50 PM Re: Cross domain problem for iframe
Skilled Talker

Posts: 95
Trades: 0
Quote:
Originally Posted by funkdaddu View Post
It's a security issue, you can't target frames/windows/pages from other domains. So you couldn't do something like open an eBay login window and change the form action to go to another server. Put both pages on the same server to fix the problem. Maybe try putting the iframe in there as the full height, but wrapped in a DIV with overflow:hidden, then change the div's height?
Whoa security issues are really bad. The last thing I want is vunarabilities otherwise hackers could exploit it. I recommend there be no vunerabilities. That way our internet will be more secure.
hyipo is offline
Reply With Quote
View Public Profile
 
Old 08-07-2006, 03:02 AM Re: Cross domain problem for iframe
Junior Talker

Posts: 4
Name: Sadanandam
Trades: 0
Thanx guys for your responses.

But I need to use iframe to display ad. Publisher page is in different domain and the ad is from different domain? The requirement is ad should be displayed iframe.

So do you think that there is no way to use iframe in this case?
sadanandam is offline
Reply With Quote
View Public Profile
 
Old 08-07-2006, 05:23 AM Re: Cross domain problem for iframe
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
BTW your <style></style> block should be inside the document head (as should your your javascript definitions.

scrollbars:no; is NOT a CSS property:value.
the <!-- --> (comment tags) should not be in your style block
you have missing quotes around name, class & border values.


apart from that you can certainly use an IFrame to display the ad, just not the javascript in the iframe to alter it's height
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-30-2007, 03:40 AM Re: Cross domain problem for iframe
Junior Talker

Posts: 4
Trades: 0
hi
i also have the same kind of problem
i need to count the no of script requests in a cross domain scenario
i am using using
Code:
 if((n=calculate(document.getElementsByTagName('script')))<6  )
and in the calculate function i have a top.countscript and i increment it everytime the function is called but i cant get the count of countscript from previous page's request it always comes as nill
whereas if i request the script more than 5 times from same page it displays the output correctly i cant seem to get the cross domain request properly
rohitchawla is offline
Reply With Quote
View Public Profile
 
Old 07-30-2007, 09:37 AM Re: Cross domain problem for iframe
Junior Talker

Posts: 4
Trades: 0
well i explain it in detail
well im trying to count the script request send in cross domain scenario
as almost all the browsers have it restricted
i need a way to get the no of request for my script when i traverse through different pages which all request this script
i need to keep a count for the no of requests for the script and if gets more than 5 then the script should display that u cannot request for this script more than 5 times
it seems to work when i call the script more than 5 times from a single webpage
but it fails when i traverse through 1 page to another which all request it
like in main.html page i have <iframe src="next.html"> and in the next.html i have <script src="sample.js"> when i click from main.html to next.html the script count should increase from 1 to 2 and if i keep on traversing through diffrent pages who all request this script, the count should increase

im using this code to check the no of count

Code:
if((n=calculate(document.getElementsByTagName('script')))<6  )
if the no of counts r less than 6 then the script should do what its supposed to do otherwise it should reply as script cant be accesed more tha 5 times

the function calculate counts the no of request for that script
i use a countScript to keep the no of count and i use

Code:
if(top.countScript==null){top.countScript=1;}else{top.countScript=top.countScript+1;}

this works fine when all requests originate from a single html page but if i traverse through multiple webpages which all request this script
the top.countScript always returns as null

i need the top.countScript to keep the no of record of requests earlier made which it doesnt

can u help me with some code that can keep the no of counts for the scripts when it is a cross domain issue
thanks in advance
rohitchawla is offline
Reply With Quote
View Public Profile
 
Old 07-30-2007, 01:25 PM Re: Cross domain problem for iframe
Junior Talker

Posts: 1
Trades: 0
Check out this work-around for the cross domain problem...
Flycs is offline
Reply With Quote
View Public Profile
 
Old 07-31-2007, 04:06 AM Re: Cross domain problem for iframe
Junior Talker

Posts: 4
Trades: 0
thanks Flycs
but it should not only pass information only through iframe.
it should send the no of counts for that requested script everytime
suppose we have the script called from two web pages page1.html and page2.html
page1.html has <script src="example.js"> and so does page2.html
and page 1 has a link to page 2 so when i click on that link the script request should increment by 1
but the counter im using always has null in the no of counts
i need a counter which can keep the count made till now and pass it to the next script request in cross domain
rohitchawla is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Cross domain problem for iframe
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.72475 seconds with 12 queries