Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: how to change the code below

  1. #1
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default how to change the code below

    In the index page, I have a link where if clicked, it will go to another webpage. Would appreciate if someone could advise on how to change the code below so that the URL of the new webpage remains the same as the index URL. Currently, when the link is clicked, it opens another window with the URL of the new webpage.

    Link in the index html file:
    <a href="javascript://" onClick="topic1()">

    Code of the js file:
    <!--
    // topic1()
    function topic1(){
    <span onClick="topic1()">
    window.open("../topic1.htm","topic1");
    }
    //-->

  2. #2
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello DUDE,

    If I am right what you want is to be able to open a link in the same window and not in a new one... Well if this is the case then all you have to do is -
    replace

    window.open

    with

    window.location

    And that is all that it is to it !!!
    window.open - opens new windows
    window.location - opens links in the same tab/page

    AND you are most WELCOME !!!

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

    Default

    Code:
    function topic1(){
    <span onClick="topic1()">
    window.open("../topic1.htm","topic1");
    }
    ^^ Is invalid for one. You can't nest HTML in JavaScript code.
    By default, the window.open() function opens in a new window regardless. Although what pcbrainbuster said is correct, you should just do a link:
    Code:
    <a href="../topic1.htm">...
    Some people may not be able to see JavaScript (their browser may think it to be a virus of some sort - in IE 5 happens all the time), and that's why you try to avoid it in places where you can.
    - Mike

  4. #4
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yeah what Mike said about the link is true in some cases is better just using javascript for anything YOU can, keeps practice...

    (although i would personally use a link - lol)

    Another thing is you can kind of nest html using the document.write method - if you need some help in this section just ask ( am at this forum about 8 hours a day(started today(lol)))

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

    Default

    document.write completely erases the page when used in the <head>. If you ever have to come to writing HTML with JavaScript, you should you the DOM method (appendChild(); ): http://slayeroffice.com/articles/inn..._alternatives/
    - Mike

  6. #6
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Thanks to both for your kind response. The codes that I used were from a free script that I downloaded from the net for my site. However I hope to change it so that a new window will not be opened and because I do not wish the URL to be displayed, I did not use the <a href> method.

    1) PCbrainbuster, I tried replacing window.open with window.location as appended below in the js file but it didn't work. Nothing happened. I wonder if I missed any thing?

    Code of the js file:
    <!--
    // topic1()
    function topic1(){
    <span onClick="topic1()">
    window.location("../topic1.htm","topic1");
    }
    //-->


    2) Mburt, would appreciate if you could advise on which DOM method (appendChild(); method to use. There are quite a number listed there and I am at a loss.

  7. #7
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    For all I know what you want is a link to a topic.html with no info in the status bar (the bottom thing giving info of links...) and so i will make the script for you - if this is a success i will feel good and if not bad lol -
    ---------
    IE
    ---------
    <script>
    function topic1() {
    window.location="http://www.(full path here, it is easier that way)"
    }
    </script>

    Just remove everything between including the brackets and type down your site address there between the the two quotes. Also give the button an event to fire the script. This script should just open the site in the window and that's it.

    And now i will show you how to create a script that will display nothing in the status bar !!!

    <script>
    function removestatus() {
    window.status=""
    }
    </script>

    put your message between "" or leave it to keep the bar blank also set the event for the script in all the links - use onmouseover or onmouseenter.

    To set the bar back to default replace window.status with window.status=window.defaultStatus
    and use onmouseout or onmouseleave for that.

    Does it help???
    Last edited by pcbrainbuster; 02-19-2007 at 11:42 PM.

  8. #8
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much for your time and patience.
    I tried both script that you gave but they didn't work

  9. #9
    Join Date
    Feb 2007
    Posts
    601
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmmm, i do not know exactly what went wrong seeing how they work for me.

  10. #10
    Join Date
    Nov 2006
    Posts
    55
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    I wonder if I misinterpreted you earlier? Appended below are the codes that I used based on the one that you provided:

    Link in the index html file:
    <a href="javascript://" onClick="topic1()">

    Code of the js file:
    <script>
    function topic1() {
    window.location="http://www.domain/topic1.htm"
    }
    </script>

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
  •