我目前正在测试一些GMOD LUA HTML请求/回调函数,但似乎找不到解决此问题的方法。
代码:
local url;
if CLIENT then
local dframe = vgui.Create("DFrame")
dframe:SetSize(ScrW()*0.75, ScrH()*0.85)
dframe:SetTitle("Youtube video player...")
dframe:SetDraggable(true)
dframe:Center()
dframe:MakePopup()
local width, height = dframe:GetSize()
local dhtml = vgui.Create("DHTML", dframe)
dhtml:SetSize(width, height-ScrH()*0.1)
dhtml:Dock(TOP)
dhtml:OpenURL("http://www.youtube.com")
dhtml:AddFunction("luaResponse", "sendURL", function(URL)
url = URL
print("URL = "..URL)
end)
local dbutton = vgui.Create("DButton", dframe)
dbutton:SetText("Play this video")
dbutton:Dock(FILL)
dbutton:DockMargin(0, dframe:GetDockPadding(), 0, 0);
dbutton.DoClick = function()
dhtml:RunJavascript("luaResponse.sendURL(window.location.href);")
print("hello")
dframe:Close()
end
end
当我单击d按钮时,它将在控制台中打印“ hello”并关闭dframe,但是它不执行javascript函数。
完整错误报告:
[HTML] :1: Unsafe JavaScript attempt to access frame with URL https://pubads.g.doubleclick.net/gampad/ads?sz=850x250&gdfp_req=1&ad_rule=0&iu=/4061/com.ythome&impl=ifr&loeid=23773251,23757209,23771404,23761460,23769156,23775644&scp=ssl%3D1%26dc_yt%3D1%26klg%3Den%26kmyd%3Dvideo-masthead%26ytdevice%3D1%26ytexp%3D23762434,9471239,23771404,9406993,9441347,23772824,23775003,23773605,23770800,23774273,9458115,9456196,23723593,23750996,23711319,23769434,23773787,23733598,23772895,23726562,23754731,23766770,23720702,9477942&d_imp=1&ytdevice=1&pucrd=CgYIABAAGAB4Ag&correlator=9155972215812654 from frame with URL https://www.youtube.com/embed/whGR4q0vK-8?mute=1&rel=0&iv_load_policy=3&start=0&adformat=1_8&enablejsapi=1&controls=0&modestbranding=1&showinfo=0&autoplay=1&nologo=1&widget_referrer=https%3A%2F%2Fpubads.g.doubleclick.net%2Fgampad%2Fads%3Fsz%3D850x250%26gdfp_req%3D1%26ad_rule%3D0%26iu%3D%2F4061%2Fcom.ythome%26impl%3Difr%26loeid%3D23773251%2C23757209%2C23771404%2C23761460%2C23769156%2C23775644%26scp%3Dssl%253D1%2526dc_yt%253D1%2526klg%253Den%2526kmyd%253Dvideo-masthead%2526ytdevice%253D1%2526ytexp%253D2376243&origin=https%3A%2F%2Fwww.youtube.com&widgetid=1. Domains, protocols and ports must match.
使用GMOD LUA的人并不多,因此很难在Internet上找到解决方案。因此,Stackoverflow是我的最后希望。
非常感谢。