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.


 Subscribe in a reader

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

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Jul 25th, 2007, 02:31
Junior Member
Join Date: Jul 2007
Location: Sydney
Age: 27
Posts: 27
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Jul 25th, 2007, 08:41
Most Reputable Member
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Jul 25th, 2007, 11:32
Most Reputable Member
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Jul 25th, 2007, 23:45
Junior Member
Join Date: Jul 2007
Location: Sydney
Age: 27
Posts: 27
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #8  
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #9  
Old Jul 26th, 2007, 23:38
Junior Member
Join Date: Jul 2007
Location: Sydney
Age: 27
Posts: 27
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #10  
Old Jul 26th, 2007, 23:45
Rob's Avatar
Rob Rob is online now
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,194
Blog Entries: 7
Thanks: 27
Thanked 24 Times in 21 Posts
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.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #11  
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #12  
Old Jul 28th, 2007, 00:32
Rob's Avatar
Rob Rob is online now
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,194
Blog Entries: 7
Thanks: 27
Thanked 24 Times in 21 Posts
Re: Javascript to change Base href?

Closed... as requested!
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
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 20:56.


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