I have the following script:
<script language="text/javascript">
document.getElementById("eagle").src="http://path.com:8000/OA_HTML/1.gif";
</script>
And html:
<img id="eagle" src="godlo.gif" width="60" height="60"/>
I won't JS to change path of the image, but stays the same. Why won't this work? In js fidle it works perfectly fine, so why won't this work in xslt? Maybe there is a wayaround?
UPDATE
I have edited this post to add xsl file. Although I don't think it is necessary here.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="html"/>
<xsl:template match="*">
<html>
<head>
<title>D</title>
</head>
<script language="text/javascript">
document.getElementById("eagle").src="http://example.com:8000/OA_HTML/1.gif";
</script>
<body>
<p style="text-align:center;"><img id="eagle" src="1.gif" width="60" height="60"/></p>
</body>
</html>
</xsl:template>
Your script does not know where is eagle
, place your script below the img
tag. Also need to change <script language="text/javascript">
to <script type="text/javascript">
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="html"/>
<xsl:template match="*">
<html>
<head>
<title>D</title>
</head>
<body>
<p style="text-align:center;"><img id="eagle" src="1.gif" width="60" height="60"/></p>
</body>
<script type="text/javascript">
var picurl = window.location.protocol+"//"+window.location.hostname+"/OA_HTML/godlo.gif/>";
document.getElementById("eagle").src="http://example.com:8000/OA_HTML/1.gif";
</script>
</html>
</xsl:template>
Solution posted by @Ishank Gupta in comment was correct:
Changing <script language="text/javascript">
to <script type="text/javascript">
did the trick.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.