Entering the following code in the URL bar (in safari) creates the required script tag and button in order to run Together.js:

javascript:{var s=document.createElement('script');
s.src='https://togetherjs.com/togetherjs-min.js';
document.head.appendChild(s);
var b=document.createElement('button');
b.onclick='function(){TogetherJS(this); return false;}';
b.innerHTML='Start TogetherJS';document.body.appendChild(b);} 

However, the onclick property of the button is not set. I have also tried setting the onclick property to a string value but have had no luck. How can I set the onclick property of the button?

PS. This is one of my first questions. Is there any thing I could improve?

有帮助吗?

解决方案

eval is actually not recommended but for your example this should work:

  b.onclick=eval('function clickHandler(){TogetherJS(this); return false;}');

or better use this:

  b.onclick=function(){TogetherJS(this); return false;};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top