Javascript to change Base href?

This is a discussion on "Javascript to change Base href?" within the JavaScript Forum section. This forum, and the thread "Javascript to change Base href? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 24th, 2007, 11:38
Reputable Member
Join Date: Jul 2007
Location: Windsor, ON, Canada
Age: 19
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Javascript to change Base href?

Is there a way to use javascript to change the base href at one point in the document, then change it back to the original? I need to do it for some images.

  #2 (permalink)  
Old Jul 25th, 2007, 02:31
Junior Member
Join Date: Jul 2007
Location: Sydney
Age: 26
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

Depending at which point you mean, it may be better to do this with CSS.
Could you post some example code?
  #3 (permalink)  
Old Jul 25th, 2007, 08:41
SuperMember

SuperMember
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

You can use the setAttribute property which is pretty straightforward. What exactly are you doing though, I don't really follow.


Pete.
  #4 (permalink)  
Old Jul 25th, 2007, 11:14
Reputable Member
Join Date: Jul 2007
Location: Windsor, ON, Canada
Age: 19
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

Quote:
Originally Posted by pa007 View Post
You can use the setAttribute property which is pretty straightforward. What exactly are you doing though, I don't really follow.


Pete.
just something to save code, as the thumbnails are on photobucket for the moment, so i just want to have some javascript change the base href at the start of the thumbnail section, then change it back to the original at the end of the section.

thanks.

edit: just tried it, nope, didn't work.

Code: Select all
<script type="text/javascript">
document.getElementById('myBase').setAttribute('href','http://i91.photobucket.com/albums/k312/ZumoroNuva/SquareThumbs/');</script>
and i made sure the base's id="myBase", i also tried it with just the URL in quotes and neither in quotes

Last edited by Zonglars; Jul 25th, 2007 at 11:25.
  #5 (permalink)  
Old Jul 25th, 2007, 11:32
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

Quote:
Originally Posted by Zonglars View Post
just something to save code, as the thumbnails are on photobucket for the moment, so i just want to have some javascript change the base href at the start of the thumbnail section, then change it back to the original at the end of the section.
This won't work, because base href is a global attribute for the document. At best, changing it will break all your other links!
  #6 (permalink)  
Old Jul 25th, 2007, 11:35
Reputable Member
Join Date: Jul 2007
Location: Windsor, ON, Canada
Age: 19
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

ah, okay, thanks, i'll just stick with photobucket 'till i get more space and bandwidth for my site (i already have more than enough, but just to be safe)
  #7 (permalink)  
Old Jul 25th, 2007, 23:45
Junior Member
Join Date: Jul 2007
Location: Sydney
Age: 26
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

I'm not exactly sure what needs to happen but I wrote the following anyway:

http://www.swallow.net.au/temp/fourPics.htm

I've put all my thumbnails in one bitmap that's 400px wide by 100px high. This way I don't have to worry about preloading all the thumbnails. Then set the bitmap to the background and just adjusted the background position for each div.

Saves code, no preloading and you can use JS to change the css if you need the background pos to change at a certain point.

Still I may have completely missed the point here.

Last edited by AndrewFelix; Jul 26th, 2007 at 05:24.
  #8 (permalink)  
Old Jul 26th, 2007, 11:53
Reputable Member
Join Date: Jul 2007
Location: Windsor, ON, Canada
Age: 19
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

oh, you did.

i'm talking about the base tag in the header, that sets the default url for relative links and optionally the default target for links.

i have know clue what you thought i meant
  #9 (permalink)  
Old Jul 26th, 2007, 23:38
Junior Member
Join Date: Jul 2007
Location: Sydney
Age: 26
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

ha ha...I obviously got that completely arse up. My brain was pretty scattered yesterday.
  #10 (permalink)  
Old Jul 26th, 2007, 23:45
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: Javascript to change Base href?

In full agreement with Mike, I have to re-iterate what he said....

I.e... the BASE attribute is applied at a document level. You can get to the attribute via javascript but the setting will take the 'last applied' value and apply at a per document level (not part of the document which is what you need)

Maybe you could explain further what you are trying to achieve as there will almost certainly be a better and more enlightening way to achieve the same result you are after.
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
  #11 (permalink)  
Old Jul 28th, 2007, 00:30
Reputable Member
Join Date: Jul 2007
Location: Windsor, ON, Canada
Age: 19
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript to change Base href?

it doesn't really matter actually, it wouldn't save that much code anyway, so someone can just close this, not important.
  #12 (permalink)  
Old Jul 28th, 2007, 00:32
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
Re: Javascript to change Base href?

Closed... as requested!
__________________
Rob - SEO Specialist
Owner & Founder of Webforumz.com

I am currently unavailable for private work
Closed Thread

Tags
base, href, javascript

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
change the 'src' value using javascript grglaz JavaScript Forum 5 Jan 6th, 2008 21:50
Javascript detect Flash, change CSS? bigd JavaScript Forum 0 May 3rd, 2007 08:20
href and javascript rksathishkhumar JavaScript Forum 4 Nov 8th, 2006 13:13
[SOLVED] How To: Change characters in a textarea? Using Javascript Anonymous User JavaScript Forum 0 Feb 16th, 2005 12:34
how do u change the content of a <div> with javascript benbacardi JavaScript Forum 4 Jun 26th, 2004 19:14


All times are GMT. The time now is 04:50.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43