Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Location
    Chicago
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Script needs to open in same window -

    Hello.

    I'm brand new here & fairly new to JavaScript. I hope this is an appropriate question for this forum.

    I got a simple free JavaScript slideshow from the same site that referred me to your forum:

    http://www.javascriptkit.com/script/.../jsslide.shtml

    My question - can this code be modified so the link opens up in the same window instead of a new one? I presume any changes would occur in the Head portion of the script, but everything I've tried was uneventful.

    Thank you very much for your assistance.


    Stefano

    ***

    This part goes in the Head section:

    Code:
    <script language="JavaScript1.1">
    <!--
    
    /*
    JavaScript Image slideshow:
    By JavaScript Kit (www.javascriptkit.com)
    Over 200+ free JavaScript here!
    */
    
    var slideimages=new Array()
    var slidelinks=new Array()
    function slideshowimages(){
    for (i=0;i<slideshowimages.arguments.length;i++){
    slideimages[i]=new Image()
    slideimages[i].src=slideshowimages.arguments[i]
    }
    }
    
    function slideshowlinks(){
    for (i=0;i<slideshowlinks.arguments.length;i++)
    slidelinks[i]=slideshowlinks.arguments[i]
    }
    
    function gotoshow(){
    if (!window.winslide||winslide.closed)
    winslide=window.open(slidelinks[whichlink])
    else
    winslide.location=slidelinks[whichlink]
    winslide.focus()
    }
    
    //-->
    </script>
    This part goes in the Body section:

    Code:
    <a href="javascript:gotoshow()"><img src="food1.jpg" name="slide" border=0 width=300 height=375></a>
    <script>
    <!--
    
    //configure the paths of the images, plus corresponding target links
    slideshowimages("food1.jpg","food2.jpg","food3.jpg","food4.jpg","food5.jpg")
    slideshowlinks("http://food.epicurious.com/run/recipe/view?id=13285","http://food.epicurious.com/run/recipe/view?id=10092","http://food.epicurious.com/run/recipe/view?id=100975","http://food.epicurious.com/run/recipe/view?id=2876","http://food.epicurious.com/run/recipe/view?id=20010")
    
    //configure the speed of the slideshow, in miliseconds
    var slideshowspeed=2000
    
    var whichlink=0
    var whichimage=0
    function slideit(){
    if (!document.images)
    return
    document.images.slide.src=slideimages[whichimage].src
    whichlink=whichimage
    if (whichimage<slideimages.length-1)
    whichimage++
    else
    whichimage=0
    setTimeout("slideit()",slideshowspeed)
    }
    slideit()
    
    //-->
    </script>
    <p align="center"><font face="arial" size="-2">This free script provided by</font><br>
    <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
    Kit</a></font></p>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    It is for the user to decide whether a page opens in the same window, a new window or a new tab.

    Most people don't want new browser windows opening any more and prefer either to have them open in a new tab or as an overlay on the current page.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Feb 2013
    Location
    Chicago
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the feedback. A little more background for you.

    The slideshow is intended to be used an internal link to another page within my site. 99% of the links on my site are internal; therefore, they all open in the same window. For continuity, I want the slideshow to do the same.

    The script in question forces open a new window. I want to override that. Is this a possibility?

    I appreciate any assistance or alternative recommendations. Thank you very much.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    The second parameter of window.open() is a string representing the name of the target window.

    Set it to: "_self"

    Code:
    winslide=window.open(slidelinks[whichlink], '_self', false);
    Be aware that your code is very antiquated.

    <script language=javascript> is long deprecated and obsolete. Use <script type = "text/javascript"> instead (in fact also deprecated but still necessary for IE<9).
    The <!-- and //--> comment (hiding) tags have not been necessary since IE3 (i.e. since September 1997). If you see these in some published script it is a warning that you are looking at ancient and perhaps unreliable code.
    Last edited by Philip M; 02-12-2013 at 04:11 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    -x-x- (02-12-2013)


  •  

    Posting Permissions

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