www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to change http to https for links

  1. #1
    Join Date
    Feb 2009
    Posts
    3

    How to change http to https for links

    How can I change the links for a given domain from http to https? For example: http://www.domain.com would become https://www.domain.com

  2. #2
    Join Date
    Jun 2007
    Posts
    667
    Quote Originally Posted by LuiePL View Post
    How can I change the links for a given domain from http to https? For example: http://www.domain.com would become https://www.domain.com
    Presumably you don't control the rendering of the document but you can insert a script into it?
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Change Link Protocol</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <p>
    <a href='http://mydomain.com'>LINK</a>
    <a href='http://mydomain.com/nuts/r/us?b=2'>LINK</a>
    
    <script type="text/javascript">
    
    (function http2https( theDomain )
    {
     var dl = document.links, len = dl.length, re = new RegExp( "^http:(\/\/" + theDomain +".*)" );
    
     for( var i = 0; i < len; i++ )
      dl[ i ].href = dl[ i ].href.replace( re, "https:$1");
      
    })( "mydomain.com" );
    
    </script>
    
    </body>
    </html>

  3. #3
    Join Date
    Feb 2009
    Posts
    3
    Quote Originally Posted by Sterling Isfine View Post
    Presumably you don't control the rendering of the document but you can insert a script into it?
    I am trying to write a greasemonkey script that incorporates this function.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles