Hey... Just a quick question regarding the replace method in javascript. I have the following html document to replace an url (oldurl) for another url (newurl): <a id="link" href="http://oldurl.com">Old Url</a> <script type="text/javascript"> var [I]oldurl[/I] = document.getElementById('link'); var [I]newurl[/I] = oldurl.replace("http://oldurl.com", "http://newurl.com"); document.write('<iframe src="' + [I]newurl[/I] + '" width="500" height="500"></iframe>'); </script> Code (markup): But the script get stuck in the replace part and I keep getting the following error in Mozilla: oldurl.replace is not a function Code (markup): And in IE: Object doesn't support this property or method Code (markup): Any ideas? Please it's driving me crazy!
Hi there, 'oldurl' is a DOM object, not a string. Thus the error message. You may want to get the 'href' (assuming it's an anchor) and perform a replace on it. Also, the first parameter for 'replace()' should be a regular expression.
Thanks, but if the anchor is not the href attribute.,, Is there anyway other way to replace it? Thanks in advanced!
I think that should do it oldurl.href.replace( to keep it simple, the href element is a string, so now it has the method you are looking for.