The IWDN

Advanced Search





You are not logged in.

IWDN Forum Index > Web Development > Web Design, Structure and Style >> Targeting an anchor within iFrame

Reply
 
Thread Tools
Old June 18th, 2007, 17:53   #1
spambanjo's Avatar
spambanjo
Aspiring Enthusiast
 
Join Date: Jun 2007
Location: Burton, England
Posts: 24
Unhappy Targeting an anchor within iFrame

I know this question has been asked lots, although it never seems to get answered. I am a member of many forums, and have trawled through hundreds of pages of answer-less questions before finally finding the IWDN.

So... my problem... I have set up a ma-hu-sive form, using an iFramed list to replace the drop-down menus. I needed to do it in this way to allow for advanced formatting within the drop-down list (image, coloured and bold text, etc). There are lots of lists and standard dynamic drop-downs would take forever to load, so it also drastically speeds up the initial load time of the page. It only loads the dynamic drop-down data on request, and in many instances they are simply not required anyway.

I have 4 working scripts set up on the parent pageto perform the following
  1. Show/Hide/Re-Position the iFrame
  2. Target a link to the iFrame (For changing dynamic lists)
  3. Remember keypress, and if iFrame's visibility is set to 'visible', then...
  4. ...Push an anchor ( #A - #Z ) to the iFrame
All of my code is working and correct. My problem is encountered when I press a key (Let's say the 'B' key for now). Pressing 'B' should scroll down the list to all the items in the drop-down starting with 'B' (Like it does with a standard drop-down). Which it does... But....!

The problem is that the Parent page is also scrolling to the anchor position.

I am left with the iFrame's child page in the correct location as intended, but my parent page scrolls so that the iFrame is right at the top of the browser, pushing important information off screen.

Is there a way to stop the parent scrolling when I click the link.
(The parent page needs to be scrollable as the form is huge)

All my code is perfect, so please don't ask me to post my code, there are definitely no problems there.

The linking method is good old "framename.location='page.asp#anchorname';"

I simply need to know if a method exists to stop the parent-scroll from happening.
__________________
"Never underestimate the ignorance of the common man" : Spam Banjo : 2007
Sites4Biz
| Grimaldi Online | The Hell Hole | The Palm Group
spambanjo is offline   Reply With Quote
Old June 18th, 2007, 19:20   #2
kirxklox
Web-Tinker
 
Join Date: Nov 2004
Location: Dardanelle, Arkansas
Posts: 1,208
Due to the fact you are using iFrames and you have the same IDs on both pages, you are calling for both IDs to scroll.

Use different IDs on each iFrame!

#A1 on one page.
#A0 on the other.

ETC.
__________________
kirxklox (Sam Kirk)
Contact by form mail

It is not a job, but an excursion through life!
kirxklox is offline   Reply With Quote
Old June 18th, 2007, 22:21   #3
inimino
IWDN Core Team
 
Join Date: Oct 2004
Location: Colorado, US
Posts: 1,174
Send a message via ICQ to inimino Send a message via AIM to inimino
Yes, there are several ways to do this.

I have made an example of one here:

http://mjclement.com/tests/scroll/iframe/001.html

This simply saves the current scroll location of the page, jumps the iframe to the fragment, and then scrolls the page back to where it was. This creates a visible flash as the page scrolls twice. If you want to avoid the flash you can scroll the iframe without changing the href, by finding the anchor element, getting its location, and scrolling directly to that location. There is little benefit to using the correct fragment URL in an iframe since the URL is not user-visible.
inimino is offline   Reply With Quote
Old June 19th, 2007, 09:46   #4
spambanjo's Avatar
spambanjo
Aspiring Enthusiast
 
Join Date: Jun 2007
Location: Burton, England
Posts: 24
Thumbs down Not that

Quote:
Quoting kirxklox: View Post
Due to the fact you are using iFrames and you have the same IDs on both pages, you are calling for both IDs to scroll.

Use different IDs on each iFrame!

#A1 on one page.
#A0 on the other.

ETC.
Thanks for response but it wasn't that. I've had to be very careful with my naming conventions due to how many different form fields I have.
__________________
"Never underestimate the ignorance of the common man" : Spam Banjo : 2007
Sites4Biz
| Grimaldi Online | The Hell Hole | The Palm Group
spambanjo is offline   Reply With Quote
Old June 19th, 2007, 09:55   #5
spambanjo's Avatar
spambanjo
Aspiring Enthusiast
 
Join Date: Jun 2007
Location: Burton, England
Posts: 24
Thumbs up Spot On Old Chap!

Quote:
Quoting inimino: View Post
Yes, there are several ways to do this.

I have made an example of one here:

http://mjclement.com/tests/scroll/iframe/001.html

This simply saves the current scroll location of the page, jumps the iframe to the fragment, and then scrolls the page back to where it was. This creates a visible flash as the page scrolls twice. If you want to avoid the flash you can scroll the iframe without changing the href, by finding the anchor element, getting its location, and scrolling directly to that location. There is little benefit to using the correct fragment URL in an iframe since the URL is not user-visible.
Thanks for such quick responses.

Your answer was spot on and something I hadn't even considered.
Great Solution.
Thanks again!
__________________
"Never underestimate the ignorance of the common man" : Spam Banjo : 2007
Sites4Biz
| Grimaldi Online | The Hell Hole | The Palm Group
spambanjo is offline   Reply With Quote
Old June 20th, 2007, 13:27   #6
spambanjo's Avatar
spambanjo
Aspiring Enthusiast
 
Join Date: Jun 2007
Location: Burton, England
Posts: 24
Exclamation DOH!!!

Quote:
Quoting inimino: View Post
Yes, there are several ways to do this.

I have made an example of one here:

http://mjclement.com/tests/scroll/iframe/001.html
Sorry, I just tested the script in IE6 and it does not work. I will attempt to fix searching Google and will post the result back if I manage to sort it.
__________________
"Never underestimate the ignorance of the common man" : Spam Banjo : 2007
Sites4Biz
| Grimaldi Online | The Hell Hole | The Palm Group
spambanjo is offline   Reply With Quote
Old June 20th, 2007, 20:26   #7
inimino
IWDN Core Team
 
Join Date: Oct 2004
Location: Colorado, US
Posts: 1,174
Send a message via ICQ to inimino Send a message via AIM to inimino
Ah, right, I should have warned you about that. Here's an uglier version which works in IE:
http://mjclement.com/tests/scroll/iframe/008.html

and the alternative approach I hinted at, which also works in IE:

http://mjclement.com/tests/scroll/iframe/007.html

See 009 as well.
inimino is offline   Reply With Quote
Old June 21st, 2007, 10:42   #8
spambanjo's Avatar
spambanjo
Aspiring Enthusiast
 
Join Date: Jun 2007
Location: Burton, England
Posts: 24
Talking Force them to use The Fox!!!

Thank you so much. I will keep your script ready for next time!

We are designing an on-line app, so we are in a lucky position of being able to dictate what browser they use.

We are going to recommend Firefox be installed on all machines, as this would make our life much simpler, and give us far more control over the look of the site. It also means much tidier methods, like your first script can be implemented.

Who knows... maybe we will start a new wave of Firefox fans in their office.

Thanks again for all your help.

I know this is totally off topic, but I don't like to draw too much traffic to this page, so starting a thread would not be good, but could you tell me what you think of my Anti-IE Super Amazing Home Page. If you aren't sure how Anti-IE it is... try viewing it using IE! Feel free to use it as your home page.
__________________
"Never underestimate the ignorance of the common man" : Spam Banjo : 2007
Sites4Biz
| Grimaldi Online | The Hell Hole | The Palm Group
spambanjo is offline   Reply With Quote
Old June 21st, 2007, 18:34   #9
inimino
IWDN Core Team
 
Join Date: Oct 2004
Location: Colorado, US
Posts: 1,174
Send a message via ICQ to inimino Send a message via AIM to inimino
You're welcome. I like that home page, including in IE.

Developing only for non-IE browsers, when you have the option, really is much more convenient. The other modern browsers are so far ahead, it really saves development effort.
inimino is offline   Reply With Quote
Old June 22nd, 2007, 10:56   #10
spambanjo's Avatar
spambanjo
Aspiring Enthusiast
 
Join Date: Jun 2007
Location: Burton, England
Posts: 24
Smile FOX, FOX, FOX, FOX!!!!!

Quote:
Quoting inimino: View Post
You're welcome. I like that home page, including in IE.

Developing only for non-IE browsers, when you have the option, really is much more convenient. The other modern browsers are so far ahead, it really saves development effort.
Nah dude!!! You missed the point. The idea is to stop idiots who don't know any beter than IE and make them think about why exactly DO they use IE?

A lot of the non-tech people I talk to who use the net don't even realise there are alternatives.
__________________
"Never underestimate the ignorance of the common man" : Spam Banjo : 2007
Sites4Biz
| Grimaldi Online | The Hell Hole | The Palm Group
spambanjo is offline   Reply With Quote
Old June 22nd, 2007, 16:12   #11
inimino
IWDN Core Team
 
Join Date: Oct 2004
Location: Colorado, US
Posts: 1,174
Send a message via ICQ to inimino Send a message via AIM to inimino
I didn't miss the point, I was referring to your intranet app.

I think it's great that you're doing something to try to move people away from IE. I said something about another way to do this in the HTML5 thread:

http://iwdn.net/showthread.php?p=65221#post65221

Many people don't know they use IE, and are not very clear on what exactly a "browser" is, just like many people can not tell you what operating system they use. It takes quite a leap for those users to even understand what it means to use a different browser, and that this is something they can reasonably do.
inimino is offline   Reply With Quote
Old June 25th, 2007, 10:19   #12
spambanjo's Avatar
spambanjo
Aspiring Enthusiast
 
Join Date: Jun 2007
Location: Burton, England
Posts: 24
Quote:
Quoting inimino: View Post
I didn't miss the point, I was referring to your intranet app.
Ah sorry, my bad. Your spot on though. I find that the apps look much better in Firefox too. There are so many things I've tried, that don't work in IE, but just seem to be logical to Firefox. Just like being able to use ':hover' in CSS on anything other than a link. It's got limited uses, but when you want a hover colour on a table row in IE, it requires Javascript. Which everyone seems to hate. Why not employ it on every CSS tag like Firefox did... naturally!

Quote:
Quoting inimino: View Post
Many people don't know they use IE, and are not very clear on what exactly a "browser" is, just like many people can not tell you what operating system they use. It takes quite a leap for those users to even understand what it means to use a different browser, and that this is something they can reasonably do.
You have a damn good point there too. It's shocking that Micro$oft are still getting away with this sh*t. I recently installed Ubuntu (one of the GUI Linux variants) on a couple of old crappy machines. It's probably the best thing I've ever done with them. It's really opened my eyes to the way things should be with Micro$oft.

One of the machines is a Celleron 700 with 256mb RAM and on board Graphics. It runs as well as my aunties P4 1300, 1gb RAM and 32MB AGP GForce2, with Window$ XP . And can even run GIMP (Photoshop alternative, very similar) quite smoothly, where as my Aunties machine stutters like mad with both Photoshop or GIMP for Windows. She has no Anti-virus running and I tweaked services, etc. Although it realy helped the machine, it's still not as good as the old Celleron w/Ubuntu!!!!
__________________
"Never underestimate the ignorance of the common man" : Spam Banjo : 2007
Sites4Biz
| Grimaldi Online | The Hell Hole | The Palm Group
spambanjo is offline   Reply With Quote
Old July 12th, 2007, 12:19   #13
josh4264
Newcomer
 
Join Date: Jul 2007
Posts: 2
I'm having a similar problem on a page I'm working on, but here I'm trying to link from one iframe to another, not from the main page to an iframe within it. I'm working on a Mac and I've been testing in Firefox, Opera, and Safari. Inimino, your 008 works great in the first two browsers, but Safari doesn't respond at all when I click on the link. 009 works in all three programs to go from the main page to the iframe, but nothing happens in any of them if I try to go from one iframe to another.

Any idea how to work around this? I apologize if there's a simple solution I'm not seeing; I don't know the first thing about javascript.
josh4264 is offline   Reply With Quote
Old July 12th, 2007, 12:35   #14
spambanjo's Avatar
spambanjo
Aspiring Enthusiast
 
Join Date: Jun 2007
Location: Burton, England
Posts: 24
Is it online so we can take a look?
__________________
"Never underestimate the ignorance of the common man" : Spam Banjo : 2007
Sites4Biz
| Grimaldi Online | The Hell Hole | The Palm Group
spambanjo is offline   Reply With Quote
Old July 12th, 2007, 14:59   #15
josh4264
Newcomer
 
Join Date: Jul 2007
Posts: 2
I'm afraid I made a significant typo - when I wrote 008 above, I meant 007. 008 is the one that scrolls twice, and which I'd rather not use.

Unfortunately, the page is not up yet. Is it clear what the situation is though? Imagine 007.html or 009.html as the main page, except that instead of the link (and following script, for 009) being on that page, it's on another page, which shows up as another iframe on the main page.
josh4264 is offline   Reply With Quote
Reply


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump