PDA

View Full Version : Javascript and search engines



mdconnor
01-29-2007, 03:35 PM
I was wondering if anyone knew if this would be a search engine friendly link?

<a class="current"href="javascript:loadintoIframe('myframe',
'home!.html')" onClick="return handlelink (this)">Home</a>

Twey
01-29-2007, 03:39 PM
It definitely wouldn't. Never write links like that. Instead, try:
<a class="current" href="home&#37;21.html" onclick="loadintoIframe('myframe', this.href); return handlelink(this);">Home</a>You evidently haven't tested your site in a non-Javascript browser.

jscheuer1
01-29-2007, 05:15 PM
I agree with Twey. I also think that, depending upon the actual structure of the page and iframe setup, adding a target attribute for the non-javascript link might be good:


<a class="current" href="home%21.html" target="myframe" onclick="loadintoIframe(this.target,this.href);return handlelink(this);">Home</a>

And, if the onclick event doesn't do anything all that special, it could be skipped:


<a class="current" href="home%21.html" target="myframe">Home</a>

mdconnor
01-29-2007, 07:14 PM
Twey and John,

Thank you for the replies. I have tried this page with Javascript disabled and it is so sad that I put a "Things don't look right button" to load a non-Javascript page. Is there non-javascript code to load a different page when Javascript is not enabled?

Using "!" in "home!.html" may have been a poor choice of characters with more then one home.html. Why the "&#37;21"?

The onclick event leaves the active link a different color and I would like to keep it.

Twey, This code works except it refreshes the entire page. I was using iframes to avoid just that. Is there a fix?

<a class="current" href="home%21.html" onclick="loadintoIframe('myframe', this.href); return handlelink(this);">Home</a>


John, This works except it also opens a new browser window and loads my page there too. Your second example only loads my page to a new browser window but I need the onclick.

<a class="current" href="home%21.html" target="myframe"
onclick="loadintoIframe(this.target,this.href);return handlelink
(this);">Home</a>

I am using a Javascript script to adjust the height of the iframe to fit the page. Is that messing up these links?

Thanks for your help. Any further input would be appreciated.

Mike (AKA newbie)

mburt
01-29-2007, 07:19 PM
I am using a Javascript script to adjust the height of the iframe to fit the page. Is that messing up these links?
No, but you need to include a "href" property for it to be a link, and not an bookmark.

Try this:

<a href="#" class="current" href="home&#37;21.html" target="myframe"
onclick="loadintoIframe(this.target,this.href);return handlelink
(this);">Home</a>
If JavaScript is disabled though, the height/width script won't work.

Again on the URLS: Notice how if you every type in a space to a search engine, it will replace it with %20, which is how the browser reads spaces. They would definitely cause problems, so escaping the characters would be the most logical route.

mdconnor
01-29-2007, 07:54 PM
Mike,

Thanks for the reply, Your link opens a new browser window.
Are you saying that using "!" in a URL is bad?



Twey,
Your code actually opened home.html by itself in my browser window rather then in the iframe after taking out.

<SCRIPT LANGUAGE="JavaScript">
<!--
if (top == self) self.location.href = "index.html";
// -->
</SCRIPT>
Forgot it was in there.

Mike

Twey
01-29-2007, 07:58 PM
Twey, This code works except it refreshes the entire page. I was using iframes to avoid just that. Is there a fix?
[...]
Your code actually opened home.html by itself in my browser window rather then in the iframe after taking out.I assumed your handlelink() function returned false. If not, change it so it does.
Is there non-javascript code to load a different page when Javascript is not enabled?This is a very sub-standard solution. Design your non-Javascript page first, then add Javascript to implement the various effects, testing with and without Javascript all the while to make sure that nothing is being interfered with and the page still looks good without Javascript. Never design a page that relies upon Javascript.
Using "!" in "home!.html" may have been a poor choice of characters with more then one home.html.There are characters that are not allowed in URLs. These must be escaped as one (or more, for multi-byte encodings) &#37;XX , where XX is a two-digit hexadecimal representation of the character.
Your second example only loads my page to a new browser window but I need the onclick.myframe should be replaced with the name of your frame.

mburt
01-29-2007, 08:05 PM
myframe should be replaced with the name of your frame.
Oh, I assumed the OP had already named his frame "myframe". Sorry, I misread the post.

mdconnor
01-29-2007, 10:54 PM
Twey,

I took the "handlelink() function" out completely and it still does not work.

The name of my frame is "myframe".

The only JavaScript that is a real problem when JavaScript is not working is the iframe resizing. not sure how to get around that one but to have a button to another non javascript page.

The only link that works properly is my original link for some reason. It is not worth figuring out as I have already placed a friendly link in another location on the page.

I am still not sure why the "&#37;21" is in the code above. The "!" is a valid URL character.

I appreciate all of your help. It is obvious that you guys are beyond me when it comes to JavaScript but we all have to start somewhere and I am trying.

Thanks again,

Mike

Twey
01-29-2007, 11:00 PM
Thus, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters used for their reserved purposes may be used unencoded within a URL.Hm, you're right. My error, I'm too used to living by the standards of the deprecated escape() :)
I took the "handlelink() function" out completely and it still does not work. The handler must return false. If you remove the handlelink() function, you must explicitly return false; at the end of the handler.