Service Portal: Javascript in HTML Widget

warciech
Mega Contributor

Hi,

Is it possible to use Javascript in the stock HTML widget? 

I am trying to create a hyperlink in text that would take users back one page and I was thinking to use Javascript for that purpose (history.back()), but whenever I put that in the HTML, it gets formatted out and doesn't work.

Perhaps there is a better way to achieve that?

6 REPLIES 6

Upender Kumar
Mega Sage

Hi

Try below in HTML template.

 

<a href="javascript:void(0);" onClick="Return();">Back</a>
<script>
function Return(){

window.history.back();
}
</script>

 

Thanks

 

Please Hit Correct, ️Helpful depending on the impact of the response

warciech
Mega Contributor

It doesn't work. If I add it using 'View source code' option and save it, the editor automatically removes the <script> tag and its contents as well as it reduces <a> tag to only the opening and closing tag with no parameters.

Can you share screen shot..

 

Thanks

VamshiKumar
ServiceNow Employee
ServiceNow Employee

Hello, @warciech I am also running into same issue where I am not able to add script in the source code. Can you please let me know if you found any solution for this? Thank you.