Reputation: 6202
I have a URL that contains a lot of JavaScript.
I want to strip the URL of all JavaScript using of course JavaScript!
Here's my HTML
<a id="product_photo_zoom_url" href="javascript:OpenNewWindow('/PhotoDetails.asp?ShowDesc=N&PhotoNumber=3&ProductCode=TCP65GT30', 640, 480); void(0);" title="" rel="lightbox">
Basically I'd like the URL to just look like this:
<a id="product_photo_zoom_url" href="/PhotoDetails.asp?ShowDesc=N&PhotoNumber=3&ProductCode=TCP65GT30" title="" rel="lightbox">
There are many instances of this so trimming off the first and last ten characters would not be sufficient.
Get Element by ID product_photo_zoom_url would be fine.
Thank you for helping me!
Upvotes: 0
Views: 178
Reputation: 225074
Just get the text between single quotes:
var href = "javascript:OpenNewWindow('/PhotoDetails.asp?ShowDesc=N&PhotoNumber=3&ProductCode=TCP65GT30', 640, 480); void(0);";
var url = /'(.+?)'/.exec(href)[1];
Also, you shouldn't use mutliple elements with the same id
, it's invalid. id
s are meant to be unique. You should be using class
es instead. If you can, you should change them.
Upvotes: 2
Reputation:
If you just want it to run on the one anchor, you can do this:
var el=document.getElementById('product_photo_zoom_url');
el.href=/'(.*?)'/.exec(el.href)[1];
Upvotes: 2