Click to See Complete Forum and Search --> : Open link in a new window AND change the iFrame src page
PhatBloke
11-12-2009, 04:17 AM
Hi All,
I'm not sure if this would be more of a javascript question, but here goes...
I have been asked to create a link that opens a webpage in a new window and at the same time change what the iFrame in that new window displays on loading.
The link is:
<a href="#" onClick="javascript:window.open('Security.html', 'Security','status=yes,toolbar=no,width=1000,height=604');"> Security </a>
The layout of the webpage (Security.html) is a menu on the left hand side with an iFrame taking up 70% of the remaining space. My line manager's boss has asked for a link to open this webpage AND go to a specific item on the menu (that isn't in the iFrame src parameter).
In the past I simply said it wasn't possioble but I've had more and more requests for this and want to make sure.
Thanks in advance
Simon
What does the menu link open; another document or a bookmark?
donatello
11-13-2009, 02:17 PM
I can think of a couple of ways to do it... depending upon how your page is set up...
Just make a page called security2.html that has the desired daughter frame for the default.
Alternatively, you can do it with PHP.
I'm not sure if your menu scrolls the internal frame, if so you can use the anchor name tag to do it.
Scrolling inside the iframe: http://www.iframehtml.com/iframe-samples.html#scrolling-iframe
donatello
11-16-2009, 04:07 AM
EUREKA!!!
Thanks to Jet-lag, I was not able to sleep last night, and for some reason, the answer to this question popped into my head - like 3 days later, but nonetheless... I've got your answer!
You can make a page open containing any iframe daughter page you want, but it's a bit of a hack! Here's how.
There is a script, which you embed in the daughter frame that makes it ALWAYS open in the parent frame. So you simply link to the daughter frame that you want to open in the parent and VOILA! It will be forced to open in the proper parent due to a snippet of JavaScript!
Here is the JavaScript for the daughter frame:
<SCRIPT LANGUAGE='javascript'>try { if (top == self) {top.location.href='test.html'; } } catch(er) { } </SCRIPT>
shopgirl10
04-07-2010, 02:20 AM
hi,
i know this forum was created a long time ago but perhaps you could help me on this? I have this same purpose that i want to achieve, would you be so kind enough to share the full code for this?
i am not a programmer reason why i cannot understand some parts of the script. although i know html and javascript basics, this is just not enough for me to understand what you explained here.
If it's alright with you, i would like to request for the full code so i could try this out on my end?
waiting for your soonest response.
thank you.
@ shopgirl10: please don't dig-up old threads. Starting your own thread would have been more appropriate.
Are your requirements to open a new window and load an iframe contained in the parent document?
shopgirl10
04-07-2010, 09:20 PM
@fang: sorry about that, thought if i would reply from the same thread, it would be easier to raise my problem. I appreciate your prompt response by the way.
i am not quite sure if i understand your question (sorry), but here's the dilemma i am dealing with now: i have www.example.com as our company's website, i put a link on this site directing users to another website (www.linktoanexternalwebsite.com) not hosted by us. the iframe is applied to the external website which is opened in another window. i created an html file (iframetest.html) where the external website will be contained. I have no problems if i have only one link to cater. Currently, i have 100 links to direct to the iframetest.html page but i dont know if it's possible to put all 100 links inside the html file or do i need some condition scripting?
i have this code (iframeset.html):
<iframe src="http://www.linktoanexternalwebsite.com" name="frame1" scrolling="auto" frameborder="no" align="center" height = "100%" width = "100%">
</iframe>
like i said above, i want to put more 100 more links (www.linktoaneexternalwebsite2.com, www.linktoaneexternalwebsite3.com, www.linktoaneexternalwebsite4.com. etc.) inside the html file, is this possible? if not, then i guess i have to create 100 iframetest.html-like files to cater all 100 links each? is there a way to make this easier?
i hope i explained this clearly to you, please let me know if this made sense.
thank you.
Do you want all the external links to open in the iframe?
donatello
04-08-2010, 02:31 AM
Here are full instructions on how to do exactly that:
http://www.iframehtml.com/faq.html
(The first Question at the top of the page.)
shopgirl10
04-08-2010, 04:02 AM
@fong: yes i want all external links to open in iframe.
@donatello: thanks for the help, i appreciate it. I will test this out and see what happens. :)
Add this to the head of the parent document<base target="frame1">You must use complete URLs, i.e. beginning with http://
donatello
04-08-2010, 03:09 PM
Hmmm... the code seemed to work without that... but if Fang posted it and it involves JavaScript... just do it!
:P
(He's the JS guru around here...)
shopgirl10
04-08-2010, 10:26 PM
hi donatello and fang,
I already read the instructions from the link you gave me but there's one thing i am concerned about -- it said smth about editing the child pages..? based from my description earlier, the links i want to open in the parent page are links to external websites which is not hosted by my company, so this means modifying the child pages is beyond my control. Considering this condition, is it still possible to achieve my requirement previously?
Sorry for troubling you with a lot of questions but I really need to make this thing work.
Thank you.
donatello
04-09-2010, 05:38 AM
hi donatello and fang,
I already read the instructions from the link you gave me but there's one thing i am concerned about -- it said smth about editing the child pages..? based from my description earlier, the links i want to open in the parent page are links to external websites which is not hosted by my company, so this means modifying the child pages is beyond my control. Considering this condition, is it still possible to achieve my requirement previously?
Sorry for troubling you with a lot of questions but I really need to make this thing work.
Thank you.
No.
Not without a screenscraper.
There is only one other way... that would be to create a different (and they may be identical) parent frame for each internal page.
Like putting a screenscraper on a page, it is risky to build too much of your site around iframed content.
@ donatello, no JavaScript required, only the base tag.