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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to make iframe target from an external page

Status
Not open for further replies.

resnak

Technical User
Feb 16, 2005
13
0
0
US
I have a web based call logging system that uses iframes to look like small windows on the main page. Inside one of the iframes I can click on a link to open a specified page in another iframe using the target attribute, like so:
Code:
<A href="viewcall.cfm?callid=232497" target="CallViewIframe">View Call</a>
What I want to be able to do is to email someone a link to a certain call log. I don't have access to the source of this file so I don't have any way to just call the main page and have it open the appropriate iframe with the appropriate source. Does anyone know of a way that I can make an iframe the target of an external link?

Justin

Dyslexics of the world: Untie!
 
You'd have to have a template page which took a parameter (i.e. the name of the link to load). You could use JavaScript to dtermine the link from the URL, and then populate the iframe, but personally, if you have server-side scripting available to you, I'd use that instead.

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Why don't you have access to the page you want changed? The best thing to do is what Dan suggests. But, if for some reason you are unable to, here's somewhat of a hack. Try formatting your links like this:
Code:
javascript:void(window.open('[URL unfurl="true"]http://yourdomain.com/mainPage.cfm','mainPage'));void(setTimeout("window.open('http://yourdomain.com/viewcall.cfm?callid=232497','CallViewIframe')",[/URL] 1000));

The "1000" makes it wait 1 second to ensure the iframe exists.

Adam
 
Hello =)

I hope I'm right in understanding what you say. Let me use the following as an example. If I do understand correctly, the above example might not be suitable where a user cannot display javascript URLs, say on a bulletin board for example. SO...

INDEX.HTM is the page with the relevant iframe and the source of this iframe is viewcall.htm. Now, you want to link to it somehow, but obviously not to viewcall.htm directly because it will be viewed as the page itself and not in the context of index.htm or in an iframe.

This offers a possible solution, but I find it is rather temperamental. It doesn't seem to work in FireFox, although some adequate modifications might suffice. I don't advise jumping the gun and sticking this straight into a productive site, but hopefully it can give you some guidance.

In INDEX.HTM, you obviously need the iframe, although you don't need a source file to point to since links will do this.

At a suitable location on the page, bearing in mind the page will scroll to this location, so it might be best as the first code after the <body>, insert something similar to the following...

<a href="#" id="viewcall" onfocus="load()"></a>
<script>
function load()
{ CallViewIframe.location.href="viewcall.htm" }
</script>

In the target file, insert the following into the <head>, modifying where necessary (it need to target index.htm, so it might be "index.htm#viewcall" or "../#viewcall" or whatever...

<script> if (self.location==top.location) self.location = "#viewcall"</script>

...which will mean if anyone links to viewcall.htm, they will be redirected to index.htm.

Now, once you have this set out correctly, you can link to it...

http://[domain]/index.htm#viewcall or
http://[domain]/#viewcall

What is happening here is #viewcall is targetting the relevant ID and the page then scrolls to it. In doing so, the focus is set on it, meaning we can then use onfocus to pass commands to it, as above. There is a problem however, it's possible that everytime the focus is regained on this ID, an event will occur if you have one set on it. For that reason, I advise putting this into the <body> tag and also into the <iframe> tag...

onLoad="self.focus()"

...so as to give focus to the body or the iframe immediately after the <a href> has been focused. Failing this, it's possible a loop can occur, particularly if you use an alert or confirm box.

Sorry this is a bit wayward, but I spent an entire night trying to get my head around this exact scenario and it's the best I come up with!

Hope this Helps,
M_M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top