/    Sign up×
Community /Pin to ProfileBookmark

JavaScript hash work in quirks mode, but not in standards mode.

Hi,

I am trying to write some JavaScript that locations to a hash. I use something like this.

[CODE]
window.location.hash = “#anchor”+anchorNumber;
[/CODE]

The problem is I use the same code in two different pages. One is in quirks mode ie8, and one is in standards mode ie8. The one in quirksmode works, the one in standrds mode doesn’t.

Any idea what could cause such a thing? I know hash can work in standards mode. However, do you have any idea what is wrong? I am kind of searching for a needle in a hay stack, here.

Thanks,
Grae

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jun 28.2010 — It shouldn't really have anything to do with the JavaScript. But perhaps this is the issue. Is it an id or a name you are jumping to? Try an id, or both.<div name="anchor1" id="anchor1">
Copy linkTweet thisAlerts:
@KorJun 29.2010 — [B]anchorNumber[/B]

I suspect that is a [I]number[/I]. That means you have an element with a name="34", or something like that. Well, that is HTML illegal, as the [B]name[/B] (and [B]id[/B]) token [I]must start with a letter[/I], not with a digit.

On the other hand, [B]name[/B] is a HTML attribute which is to be used for form's elements, links, anchors, images and frames/iframes. Don't give a name to a DIV element. Some browsers won't like that. Use a classical anchor (<a name="myanchor"></a>)
Copy linkTweet thisAlerts:
@caalipauthorJun 29.2010 — Thanks, to both of you.

It was I didn't put anchors in the page. However, thanks for both your responses, they were both excellent ideas.

I hope I didn't waste too much of your time.

Grae
Copy linkTweet thisAlerts:
@Declan1991Jun 29.2010 — It was I didn't put anchors in the page.[/QUOTE]
It's always the simple things!

I meant to advise you as well, always [url=http://validator.w3.org/]validate[/url] your HTML when you have DOM problems. It might save you a lot of trouble.
×

Success!

Help @caalip spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...