在窗口中不工作的onclick事件
onlick event not working within a window.open
我试图实现一个onclick事件一次窗口。Open已经打开了。这样,当用户点击新窗口中的按钮时,它就会工作。
如果onclick事件不在新打开的窗口内,则该事件有效。
<div class="show-dialog" id="content">
<script type="text/javascript">
var c = document.getElementById("content");
function resizeText(multiplier) { if (c.style.fontSize == "") {c.style.fontSize = "1.0em"; } c.style.fontSize = parseFloat(c.style.fontSize) + (multiplier * 0.2) + "em"; }
</script>
<a href="javascript:void(0);" onclick="resizeText(1)" id="plustext">Make text bigger</a>
<a href="javascript:void(0);" onclick="resizeText(-1)" id="minustext">Make text smaller</a>
</div>
javascript函数允许点击链接和增加或减少文本。开放。窗口函数打开新的窗口,这是好的,工作很好,但在我的窗口。打开示例,onlick事件不触发。所以我不能使用函数:(
<span class="Show"><a href="#">Show<i class="fa fa-external-link-square fa-left"></i></a></span>
$(".Show a").click(function() {
var e = $(this).parent().next("div.show-dialog").html();
var t = window.open("", "mywindow1", "width=950,height=550,scrollbars=yes,toolbar=yes,menubar=yes");
t.document.write("<html><head>");
t.document.write("<style>body{font-size:2em;}</style>");
t.document.write("<script type='text/javascript'>
var c = document.getElementById('content');
function resizeText(multiplier) {
if (c.style.fontSize == '2em')
{ c.style.fontSize = '2em'; } c.style.fontSize = parseFloat(c.style.fontSize) + (multiplier * 0.2) + 'em';
}
</script>");
t.document.write("</head><body>");
$(t.document).find("body").html(e);
t.document.write("<a href='javascript:void(0);' onclick='resizeText(1)' id='plustext'>Make text bigger</a>
<a href='javascript:void(0);' onclick='resizeText(-1)' id='minustext'>Make text smaller</a>");
t.document.write("</body>");
t.document.write("</html");});
最后我设法让onclick甚至在window.open.
我还集成了一个函数来增加和减少窗口内的字体大小。开放的onclick。
// Creating window to open for text that are in div with class name show-dialog
$(".Show a").click(function() {
// Varible grabs content of show dialogs
var activityContent = $(this).parent().next("div.show-dialog").html();
// Establish varibale to create buttons to increase text
var userGUI = "<div class='userGUI'><a href='javascript:void(0);' onclick='resizeText(1)' id='plustext'><i class='fa fa-plus-square-o fa-2x'></i></a>
<a href='javascript:void(0);' onclick='resizeText(-1)' id='minustext'><i class='fa fa-minus-square-o fa-2x'></i></a><br>Increase / Decrease font size.</div>";
// Created variable for the window.open
var inWindow = window.open("", "mywindow1", "width=950,height=550,scrollbars=yes,toolbar=yes,menubar=yes");
// Writing to the inWindow variable
inWindow.document.write("<html><head>");
inWindow.document.write("<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'><link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>");
inWindow.document.write("<title>Hello world</title>");
inWindow.document.write("<style>body{font-family: 'Open Sans', sans-serif; font-size: 18px; line-height: 1.8;}a{color:#663366;}a:hover{color:#844484;}.userGUI{float:right;}</style>");
inWindow.document.write("</head><body id='content'>");
$(inWindow.document).find("body").append(userGUI);
$(inWindow.document).find("body").append("<br><br>");
$(inWindow.document).find("body").append(activityContent);
inWindow.document.write("</body><script type='text/javascript'>
// Increase font size function
function resizeText(multiplier) {
var c = document.getElementById('content');
if (c.style.fontSize == '')
{ c.style.fontSize = '1.175em'; } c.style.fontSize = parseFloat(c.style.fontSize) + (multiplier * 0.2) + 'em';
}</script></html>");
inWindow.document.write("");
inWindow.document.close();
});
这个的html是在我的问题上面^.
相关文章:
- 如何在执行此特定onclick事件时执行JavaScript函数
- 如何调用“;链接_;在onclick事件上使用Javascript
- 如何使用jquery迭代具有相同属性的html元素并查找onclick事件
- 选择onclick事件jquery
- 执行php函数的onclick事件的其他替代方案
- 动态创建OnClick事件Javascript
- onClick事件未触发reactjs
- 使用java脚本更改onClick事件中菜单选项卡的颜色
- 如何使用OnClick事件通过参数调用来调用PHP函数
- 使用jQuery动态添加onClick事件
- onclick事件不'不要在萤火虫或铬中点火
- 如何向onClick事件处理程序传递一个接受参数的函数,并且仍然将该函数绑定到组件's”;这个“;上下文
- xPages标签onclick事件不'不要在空白处工作
- 用beautifulsoup-python调用onclick事件
- 使用JavaScript将onclick事件与参数绑定
- 使用onClick事件扩展Aviarc容器小部件
- 在按钮的onclick事件上将字符串传递给JavaScriptFuntion
- 用于显示onclick事件计数的可调整跨度标记
- Javascript onclick事件在第一次单击时未启动
- 如何使用onclick事件触发此代码.我尝试过,但失败了