Current location: Hot Scripts Forums » General Web Coding » JavaScript » image url converter script? Is this possible??


image url converter script? Is this possible??

Reply
  #1 (permalink)  
Old 12-31-05, 02:48 PM
recedo recedo is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
image url converter script? Is this possible??

Hi,

Not sure if this is possible but thought I'd ask/discuss it here...

Right, I am getting to a stage with my website where I feel an ssl certificate would benefit my customers (I currently use PayPal so it's not required but think it would boost confidence). The trouble is that the way my site has been created there are several places (that would be accessed via https://) where I have had to link to images with their full url instead of relative (eg http://www.site.com/images/image1.gif). This is something that I cannot change due to various software limitations.

Now, is there a way to do this with Javascript...

Look at the url that has been accessed. If it begins with http:// make no changes, but if it begins with https:// change all the links that contain (for example) http://www.sitename.com/images/ to https://www.sitename.com/images/.

I would think this could be done but can't be sure and don't have a clue how it would be done!

This is something that would fix a lot of re-designing on my site and would stop users getting unsecure item messages.

Any help would be appreciated.

Simon
Reply With Quote
  #2 (permalink)  
Old 01-05-06, 07:54 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Code:
<script>
function fixURL(){
	if(document.location.protocol=="https:"){
		lnks=document.getElementsByTagName('a')
		for(var i=0;i<lnks.length;i++){
			lnks[i].href=lnks.href.replace(/^http:/,"https:")
		}
	}
}
</script>
Run that using the onLoad event in the body tag.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #3 (permalink)  
Old 01-06-06, 11:14 AM
recedo recedo is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the code.

I'm not javascript expert, but wouldn't that just change the links from http:// to https:// ?

I wanted it to change the image tags, could I just change this line? ;

Code:
<script>
function fixURL(){
	if(document.location.protocol=="https:"){
		lnks=document.getElementsByTagName('img')
		for(var i=0;i<lnks.length;i++){
			lnks[i].href=lnks.href.replace(/^http:/,"https:")
		}
	}
}
</script>
Thanks
Simon
Reply With Quote
  #4 (permalink)  
Old 01-06-06, 10:18 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Ah, sorry, I read this line litterally:
Quote:
Look at the url that has been accessed. If it begins with http:// make no changes, but if it begins with https:// change all the links that contain...
Yes, to get the img tags instead you change that string. But you also need to change the property of the element which the script changes. Img tags use the .src property, not .href.
So here it is:
Code:
<script>
function fixURL(){
	if(document.location.protocol=="https:"){
		lnks=document.getElementsByTagName('img')
		for(var i=0;i<lnks.length;i++){
			lnks[i].src=lnks.src.replace(/^http:/,"https:")
		}
	}
}
</script>
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Raffle/Lottery Script (Very profitable!), Coded it myself. Voltaire General Advertisements 6 03-16-09 07:15 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
Raffle/Lottery Script (Very profitable!), Coded it myself. Voltaire General Advertisements 2 01-02-06 11:55 PM
Free Image Hosting / Script Sale 4n7hr4x Job Offers & Assistance 9 10-29-04 08:13 PM
small image script needed. graham barnes Script Requests 0 06-18-04 03:06 AM


All times are GMT -5. The time now is 10:59 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.