I want to execute JavaScript code in address bar of my google chrome javascript:. It works fine with something simple such as:
javascript:alert("aaa");
But it doesn't work with more than one alert. I found out that placing everything in brackets would do the trick:
javascript:{alert("aaa"); alert("blabla"); document.getElementsById("myId").innerHTML = "aa";}
But it doesn't work with something more complex such as for or calling a function. I really need to execute for like this:
var elements = document.getElementsByTagName('div');
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = "foo";
}
I tried it with both javascript: and javascript:{...} and it didn't work.
So my question is: How can I execute more complex JavaScript code such as this one above?