SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Replace url

  1. #1
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace url

    Hi.
    I've got this snippet:

    var url= window.location.href;
    var re = /index\.php/;
    var newUrl= url.replace(re, "player.htm");
    alert(newUrl);
    It works fine if the page is
    http://www.mysite.com/index.php

    but guess you it doesn't work when
    the page is
    http://www.mysite.com/

    Can you help me, please ?

    Bye.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    If you just want to change the location, you could use the following instead

    Code javascript:
    location.pathname = 'player.htm';
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    If you just want to change the location, you could use the following instead

    Code javascript:
    location.pathname = 'player.htm';
    Thanks for the tip but I've to use the
    snippet to 'load' dynamically a popup

    more code:

    YouTube.utility={
    replacePlayer:function(url){
    var re = /watch\?v=/;
    return url.replace(re, "v/");
    },
    replacePopUp:function(){
    var url= window.location.href;
    var re = /index\.php/;
    return url.replace(re, "player.htm");
    },
    popup:function(){
    var w= 425;
    var h= 350;
    var centerWidth=Math.floor((window.innerWidth/2)-(w/2));
    var centerHeight=Math.floor(screen.height-window.innerHeight);
    var features = "width="+w+",height="+h+",top="+centerHeight+",left="+centerWidth+",menubar=no,location=no,resizable=yes,scrollbars=no,status=yes,toolbar=no";
    if(WindowObjectReference == null || WindowObjectReference.closed){
    alert(YouTube.utility.replacePopUp());
    WindowObjectReference = window.open(YouTube.utility.replacePopUp(),
    "YouTubeFlashPlayer", features);
    }
    else{
    WindowObjectReference.focus();
    };
    }
    }
    a demo
    http://www.blogial.net/demo/tre/index.php


    Bye.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Then how about

    Code javascript:
    return location.protocol + '//' + location.host + '/' + 'player.htm'
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    Then how about

    Code javascript:
    return location.protocol + '//' + location.host + '/' + 'player.htm'
    It can be an idea ; ]
    Thanks for the reply.
    Sorry for the late reply my computer was broken singh!


    Bye.

  6. #6
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've changed my mind
    replacePopUp:function(){
    var url= window.location.href;
    var re = /index\.php/;
    if(!re.test(location.pathname)){
    url += 'index.php';
    }
    return url.replace(re, "player.htm");
    }
    Thanks for helping
    Bye.


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
  •