Forum Moderators: open
i need a simple command to replace one string (ie: <img src=image.jpg">) with another (ie: <iframe src="iframe.html">)
i dont even want to put up wut i've tried because its all just a mess
and the names of the files dont even have to be variables. i want to be able to replace specific strings.
any help would be appreciated
<script type="text/javascript">
var input = 'something <img src="image.jpg"> <b>whatever</b>';
var pattern = /<img src=\".*?">/g ;
var replaced = input.replace(pattern, '<iframe src="iframe.html">');
alert(replaced);
</script>
Welcome to WebmasterWorld, by the way!
Here is an example, using buttons
for the changeover, that you might
like to try...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta content="mshtml 6.00.2800.1264" name="generator" />
<title>image to iframe and back</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
#foo{position:absolute;top:20%;left:20%;display:none;}
#fool{position:absolute;top:20%;left:20%;display:block}
/*//]]>*/
</style>
</head><body>
<div>
<button onclick="document.getElementById('fool').style.display='none';
document.getElementById('foo').style.display='block'">iframe</button>
<button onclick="document.getElementById('fool').style.display='block';
document.getElementById('foo').style.display='none'">image</button>
</div><div><img id="fool" src="some.jpg"alt=""/></div>
<div><iframe id="foo"src="some.html"></iframe></div></body>
</html>
birdbrain