Jump to content

How Do I Switch The Href Attribute Using Javascript?


skaterdav85
 Share

Recommended Posts

Im currently using shadowbox and i want to pass variables through the href attribute of the shadowbox link. When i click the link though, the link does not include the query string that i concatenated in my JS function. I know the href attribute in the DOM has been changed, but i want my shadowbox link to be default2.php?box1=test, not just default2.php. Anyone know how to do that?My JS code:

function appendToURL(myURL) {	document.getElementById('addToListLink').href=myURL+"?box1=test";}

My HTML link:

<a id="addToListLink" onclick="appendToURL(this.href);" href="default2.php" rel="shadowbox;height=500;width=500">Add to list</a>

Link to comment
Share on other sites

It works in Firefox, Safari, and Opera exactly as written. That is, the href gets updated, and the browser tries to load the page with the query string. The address + query shows up in the location bar.The following is also correct code, but a bit more formal. (Notice both return statements.) If you're having problems in IE, this might clear it up. I really have no idea.

function appendToURL(myURL) {	document.getElementById('addToListLink').href=myURL+"?box1=test";	return true;}

<a id="addToListLink" onclick="return appendToURL(this.href);" href="default2.php" rel="shadowbox;height=500;width=500">Add to list</a>

If it still doesn't work, could there be other code somewhere that's interfering? When you check the DOM, are the href and onclick values what they are supposed to be?

Edited by Deirdre's Dad
Link to comment
Share on other sites

Ya, I think it is getting overwritten from something in those JS files. I need some kind of lightbox that can use an iframe so i can pass values to the lightbox and do some stuff with it. The system currently has Dojo because its bundled in a Struts package, but Dojo is horrible in my opinion. There are no examples, and the example of a lightbox diaglog I did get working was didnt look very nice. I basically need a lightbox dialog in which the js files will play nice with the Dojo library. Any suggestions?

Link to comment
Share on other sites

It's a problem that all of these people make all of these packages that all overwrite whatever events are defined. That's just a lazy way to do things. The correct solution is for the library you're using to add an event handler, not replace whatever's there. If the library is decently written it probably wouldn't be that difficult to patch it to do the right thing.

Link to comment
Share on other sites

so i looked at the JS file and its all on one line, but I went through it searching for 'href', and this is what I found. I'm not really sure if this is it and if it is, what im supposed to change. All I know is that its using object oriented JS. My guess is that it has something to do with that first line in the function.

function(link,opts){var href=link.href,obj={	el:link,	title:link.getAttribute("title"),	options:apply({},opts||{}),	content:href	};		each(["player","title","height","width","gallery"],	function(o){		if(typeof obj.options[o]!="undefined"){			obj[o]=obj.options[o];			delete obj.options[o]	}});

Link to comment
Share on other sites

That doesn't look like the issue, there's going to be an initialization method or something that scans through looking for things with "shadowbox" in the "rel" attribute and setting up the event listeners, that's the part that needs to be changed.

Edited by justsomeguy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...