[英]How can I open a javascript Window with a webpage in Tampermonkey?
So I would like to create a link for a website, and after I clicked for the link, I want to open the page in a javascript popup window. 因此,我想为网站创建一个链接,然后单击链接,然后在javascript弹出窗口中打开页面。 I created a function for this, but unfortunately I get this message in chrome console:
我为此创建了一个函数,但不幸的是,我在chrome控制台中收到了以下消息:
"Uncaught ReferenceError: myFunction is not defined"
My script looks like this: 我的脚本如下所示:
// ==UserScript==
// @name filmkodiframe
// @namespace http://neocsatblog.mblx.hu
// @description Nézd meg a filmjeidet egyszerűbben filmespolcon!
// @require http://code.jquery.com/jquery-1.11.2.min.js
// @match *://*.online-filmespolc.net/*
// ==/UserScript==
// Finnaly attach it into the DOM
$(document).ready(function() {
$('<a target="_blank" style="cursor:pointer;color:blue;hover:text-decoration:none;" title="A filmkód oldal megnyitása" class="lightview" onclick="myFunction()" id="myFrame" name="myFrame">Film</a>').appendTo('#password');
function myFunction() {
window.open("http://filmkod.uw.hu/index.php", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
}
});
I don't get it why doesn't work, because I use document ready, and the javascript under of the link. 我不明白为什么它不起作用,因为我使用的是文档就绪的以及链接下方的javascript。
只需使用jQuery事件处理程序并删除内联onclick
$('<a target="_blank"...</a>').click(myFunction).appendTo('#password');
Move the myFunction out of the document.ready function into the global namespace and it will work, like this: 将myFunction从document.ready函数中移出到全局名称空间中,它将起作用,如下所示:
window.newNamespace = {};
newNamespace.myFunction = function() {
window.open("http://filmkod.uw.hu/index.php", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
}
$(document).ready(function() {
$('<a target="_blank" style="cursor:pointer;color:blue;hover:text-decoration:none;" title="A filmkód oldal megnyitása" class="lightview" onclick="newNamespace.myFunction()" id="myFrame" name="myFrame">Film</a>').appendTo('#password');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.