Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IFrame Cross-Domain issue

Status
Not open for further replies.

PatOne

Programmer
Dec 21, 2005
3
CA
The application I am maintaining is some kind of documentary portal, where the users can select a HTML document in a list (table of content) to display it within the page.
This content can contain links, and we do not want to loose our main page. That's the reason why the content is displayed in a IFrame (and also for other historical reasons).

Now, I have been asked to add a Print Preview functionality. This would open a new window with the content that is currently displayed in the IFrame (enabling the user to see it without all the extra information our own page contains).
The customer want this preview to work whatever and wherever the content is located (can be on one of his website on the same domain but different sub-domain, or on a different domain).

As it is not possible to have the printPreview button inthe IFrame (as I do not control the page displayed), I put it in the main document.
Then, when trying to get the location.href (using
Code:
window.frames['myFrame'].location.href
) or even just trying to print the iframe (using
Code:
window.frames['myFrame'].focus();
  window.frames['myFrame'].print();
), I got a Permission denied (because of Cross-domain security, from what I figured)

So now, I should admit I have no idea of what I could do...

Any idea?

Pat
 
One way around the cross-domain issues would be to keep track of whatever document is loaded into the iframe, at the time it is loaded in (you must know this to be able to load it in to start with). Maybe store it in a session cookie, etc. Then, when you want to print, simply open a window using the URL stored in the cookie (i.e. whatever the last document opened was), and let the user use the browser controls to print it themselves.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Can`t you access the location of the iframe without the href? That would be enough to retrieve the location ...

Cheers,
Dian
 
Thanks guys for your answers.

BillyRayPreachersSon, the problem is I can know the very first document that is loaded. But I have no way to know the folowing clicks, as my users can follow any links :(

Diancecht: sorry about this "beginner" question but, how would I use the location? BTW, I need to try that, but I think the whole Location object is cross-domain secured.


Pat
 
BTW, just wondering.

From what I can read everywhere, Cross-domain security constraints should block me when my IFrame contains pages from a diferent domain.
But in my case, I should have things from portal.mydomain.com (my main page) and content.mydomain.com (content for the IFrame).

This seems to me as the same domain, just different sub-domains. But I still have the security error.

For test purposes, I have been able to have my code working by modifying the domain for both the main page and the content pages using
Code:
document.domain = document.domain.substring(document.domain.indexOf('.') + 1);
to have both pages having the exact same domain (here, mydomain.com)
But in the real life, I won't control the content that will be published by third-parties.

Any hint?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top