Results 1 to 10 of 10

Thread: Javascript and search engines

  1. #1
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Javascript and search engines

    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>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It definitely wouldn't. Never write links like that. Instead, try:
    Code:
    <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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    <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:

    Code:
    <a class="current" href="home%21.html" target="myframe">Home</a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?
    Code:
    <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.
    Code:
    <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)
    Last edited by mdconnor; 01-29-2007 at 07:32 PM. Reason: remove test code

  5. #5
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    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:
    Code:
    <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.
    - Mike

  6. #6
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- 
    if (top == self) self.location.href = "index.html";
    // -->
    </SCRIPT>
    Forgot it was in there.

    Mike

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    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.
    - Mike

  9. #9
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Quote Originally Posted by RFC1738
    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •